Get Login

J

Jose Perdigao

Good morning,
To get computer name I use HOST_NAME()
Is it possible to get the windows login through a sp or udf?

Thanks
José Perdigão
 
J

Jose Perdigao

Good afternoon

I did the folowinf function:
ALTER FUNCTION dbo.iLogin ()
RETURNS varchar(10)
AS
BEGIN
RETURN system_user
END

The return value is SQL server user name, I mean, if I logg the computer
with diferent windows user, the result is the same.

I see, system_user is the same SUSER_SNAME(), isn't it?
I would like a function to get windows login.
Thanks

giorgio rancati said:
Hi Jose

try this

select system_user

----
SYSTEM_USER
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sysusr_3c8i.asp
----

bye
--
Giorgio Rancati
[Office Access MVP]

Jose Perdigao said:
Good morning,
To get computer name I use HOST_NAME()
Is it possible to get the windows login through a sp or udf?

Thanks
José Perdigão
 
G

giorgio rancati

Hi Jose ,

What's your Authentication mode ?

In "Windows Authentication mode" the system_user returns the
DOMAIN\user_login_name.
Sql Server can't know the Windows User name if the Authentication is "SQL
Server Authentication"
 
J

Jose Perdigao

The authentication is windows NT Integrated security.
Thanks

Jose

giorgio rancati said:
Hi Jose ,

What's your Authentication mode ?

In "Windows Authentication mode" the system_user returns the
DOMAIN\user_login_name.
Sql Server can't know the Windows User name if the Authentication is "SQL
Server Authentication"

--
Giorgio Rancati
[Office Access MVP]

Jose Perdigao said:
Good afternoon

I did the folowinf function:
ALTER FUNCTION dbo.iLogin ()
RETURNS varchar(10)
AS
BEGIN
RETURN system_user
END

The return value is SQL server user name, I mean, if I logg the computer
with diferent windows user, the result is the same.

I see, system_user is the same SUSER_SNAME(), isn't it?
I would like a function to get windows login.
Thanks
 
J

Jose Perdigao

Giorgio, it's correct, winthows authentication we get domain\login
Thanks

giorgio rancati said:
Hi Jose ,

What's your Authentication mode ?

In "Windows Authentication mode" the system_user returns the
DOMAIN\user_login_name.
Sql Server can't know the Windows User name if the Authentication is "SQL
Server Authentication"

--
Giorgio Rancati
[Office Access MVP]

Jose Perdigao said:
Good afternoon

I did the folowinf function:
ALTER FUNCTION dbo.iLogin ()
RETURNS varchar(10)
AS
BEGIN
RETURN system_user
END

The return value is SQL server user name, I mean, if I logg the computer
with diferent windows user, the result is the same.

I see, system_user is the same SUSER_SNAME(), isn't it?
I would like a function to get windows login.
Thanks
 
J

Jose Perdigao

Giorgio,
Is it possibel to get the domain and login with two diferrent functions?
Thanks
Jose

giorgio rancati said:
Hi Jose ,

What's your Authentication mode ?

In "Windows Authentication mode" the system_user returns the
DOMAIN\user_login_name.
Sql Server can't know the Windows User name if the Authentication is "SQL
Server Authentication"

--
Giorgio Rancati
[Office Access MVP]

Jose Perdigao said:
Good afternoon

I did the folowinf function:
ALTER FUNCTION dbo.iLogin ()
RETURNS varchar(10)
AS
BEGIN
RETURN system_user
END

The return value is SQL server user name, I mean, if I logg the computer
with diferent windows user, the result is the same.

I see, system_user is the same SUSER_SNAME(), isn't it?
I would like a function to get windows login.
Thanks
 
G

giorgio rancati

Hi Jose ,

you can modify your function

----
CREATE FUNCTION dbo.iLogin (@Type bit)
RETURNS varchar(30)
AS
-- @Type 0 returns Domain
-- 1 returns user
BEGIN

/* Sql Server autentication mode */
IF CharIndex('\',system_user)=0
RETURN system_user

/* Windows Autentication mode */

--Domain
IF @Type=0
RETURN LEFT(system_user,CharIndex('\',system_user)-1)

--User
RETURN SUBSTRING(system_user,CharIndex('\',system_user)+1,30)

END
----

-- Get domain name
Select dbo.iLogin(0)
-- Get Login name
Select dbo.iLogin(1)

bye
 
J

Jose Perdigao

His is a really what I want.
Works perfectly,
Thanks Giorgio

jose

giorgio rancati said:
Hi Jose ,

you can modify your function

----
CREATE FUNCTION dbo.iLogin (@Type bit)
RETURNS varchar(30)
AS
-- @Type 0 returns Domain
-- 1 returns user
BEGIN

/* Sql Server autentication mode */
IF CharIndex('\',system_user)=0
RETURN system_user

/* Windows Autentication mode */

--Domain
IF @Type=0
RETURN LEFT(system_user,CharIndex('\',system_user)-1)

--User
RETURN SUBSTRING(system_user,CharIndex('\',system_user)+1,30)

END
----

-- Get domain name
Select dbo.iLogin(0)
-- Get Login name
Select dbo.iLogin(1)

bye
--
Giorgio Rancati
[Office Access MVP]

Jose Perdigao said:
Giorgio,
Is it possibel to get the domain and login with two diferrent functions?
Thanks
Jose
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top