Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting network username

Status
Not open for further replies.

AlexTekTip

Programmer
Aug 30, 2004
17
US
Hello,

Using ASP/Vbscript. Is it possible to determine the network login of the current user?

In other words. Can I create an ASP page that when requested will display the NT username of the person who requested the page?

I know this can be easily done using VB and the win32 API
advapi32.dll

Thank You.

 
Code:
<%
Dim strUser, pos, LanID,NTUserName
function GetLanID()
	strUser = request.servervariables("LOGON_USER")
	pos=instr(strUser,"\")
	GetLanID=mid(strUser,pos+1)
end function

NTUserName = GetLanID
Response.Write("The NT User Name is: " & NTUserName)
%>
 
Whoops! Correction...
Code:
<%
Dim strUser, pos, NTUserName
function GetLanID()
    strUser = request.servervariables("LOGON_USER")
    pos=instr(strUser,"\")
    GetLanID=mid(strUser,pos+1)
end function

NTUserName = GetLanID[b][red]()[/red][/b]
Response.Write("The NT User Name is: " & NTUserName)
%>
 
Thanks for the quick response. But will this actually get me the client network login?

1. We have a client computer which user uses to browse the web and is part of corporate network requiring logon (NT Authentication or LDAP).

2. We have a server computer which serves the asp page (may or may not require authentication)


Will the above code get me info for (1)?

Thanks.

 
I believe the client user must use NT authentication and the IIS machine must have anonymous authentication turned OFF (else how to recognise the user?).

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
My script will return the login minus the backslash and domain name (provided anonymous authentication is unchecked and NT authentication is checked) - Thanks Chopstik!

If you're looking for more than that then check out this script. It can easily be modified to grab more information than you want:

Here's another one worth doctoring up for your own designs:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top