Intranet NT logged user

82 views Asked by At

I have a welcome head

<h2>welcome</h2>

But I pretend get welcome to the NT logged user

this

<h2>Welcome <%response.write request.servervariables("LOGON_USER")%></h2>

gives me the DOMAIN\USER how I can only show the user? I don't want the domain appears in the text.

EDITED:

I edit this post to not create a new one. I try google but can't find any help I'm getting the correct NT-Logged user. However could I get the name of the nt-user... the corresponding one? Example: Mine NT-User is KFHM. but my name in windows is KikoFHM. At the moment I'm getting the KFHM but how to get the KikoFHM?

1

There are 1 answers

6
user692942 On BEST ANSWER

Just use Split() to separate the Domain from the Username, it uses the \ as a delimiter creating an Array with two elements, to get just the Username call the second element.

Dim username

username = Split(Request.Servervariables("LOGON_USER"), "\")(1)

This is a quick and dirty approach you can expand it and check for the \ beforehand to avoid errors, something like

Dim cred, domain, username,
cred = Request.ServerVariables("LOGON_USER") & ""
If InStr(1, cred, "\") > 0 Then
  cred = Split(cred, "\")
  domain = cred(0)
  username = cred(1)
End If

If you not interested in structuring your code at all you can always use this quick and dirty piece of code;

<%= Split(Request.ServerVariables("LOGON_USER") & "", "\")(1) %>