Discussion
If you're doing it in ASP on IIS, you can use the Request.ServerVariables("AUTH_USER") or Request.ServerVariables("LOGON_USER").
For more, see www.devguru.com/Technologies/asp/quickref/request_servervariables.html
For more, see www.devguru.com/Technologies/asp/quickref/request_servervariables.html
See below:
Dump this in an include file at the beginning of the page, you can then use the variables sUserName, sSurname, sFirstName later in your page. In our case the fullname of the user is stored as surname firstname so there is some code to switch that about - you can amend that depending on how usernames are populated in your domain.
Dump this in an include file at the beginning of the page, you can then use the variables sUserName, sSurname, sFirstName later in your page. In our case the fullname of the user is stored as surname firstname so there is some code to switch that about - you can amend that depending on how usernames are populated in your domain.
<%
'Used to collect user details
'response.AddHeader "WWW-Authenticate","Negotiate,NTLM"
Dim sUserID,sUserName,sSurname,sFirstName,iUsrGrpTot,grp,iPos,bIsQMP
sUserId = ucase(Trim(Request.ServerVariables("LOGON_USER")))
If sUserID="" then
response.write "<br>Error getting User ID<br>"
else
Set objUser = GetObject("WinNT://" & Replace(sUserId, "", "/" ))
sUserName=objUser.FullName
'Get the groups
iUsrGrpTot=0
For Each grp In objUser.Groups
iUsrGrpTot=iUsrGrpTot+1
Next
'Is this user a site admin?
bIsQMP=0
iPos=0
ReDim aUsrGrp(iUsrGrpTot)
For Each grp In objUser.Groups
'response.write grp.Name
aUsrGrp(iPos)=grp.Name
If UCase(grp.name)="DOMAINGROUPNAMEHERE" Then
bIsQMP=1
End if
iPos=iPos+1
Next
Set objUser = Nothing
iPos=InStr(sUserName, " ")
If iPos>0 Then
sSurname=Mid(sUserName,1,iPos-1)
sFirstName=Mid(sUserName,iPos+1)
sUserName=sFirstName & " " & sSurname
end If
Set iPos=Nothing
End if
%>
'Used to collect user details
'response.AddHeader "WWW-Authenticate","Negotiate,NTLM"
Dim sUserID,sUserName,sSurname,sFirstName,iUsrGrpTot,grp,iPos,bIsQMP
sUserId = ucase(Trim(Request.ServerVariables("LOGON_USER")))
If sUserID="" then
response.write "<br>Error getting User ID<br>"
else
Set objUser = GetObject("WinNT://" & Replace(sUserId, "", "/" ))
sUserName=objUser.FullName
'Get the groups
iUsrGrpTot=0
For Each grp In objUser.Groups
iUsrGrpTot=iUsrGrpTot+1
Next
'Is this user a site admin?
bIsQMP=0
iPos=0
ReDim aUsrGrp(iUsrGrpTot)
For Each grp In objUser.Groups
'response.write grp.Name
aUsrGrp(iPos)=grp.Name
If UCase(grp.name)="DOMAINGROUPNAMEHERE" Then
bIsQMP=1
End if
iPos=iPos+1
Next
Set objUser = Nothing
iPos=InStr(sUserName, " ")
If iPos>0 Then
sSurname=Mid(sUserName,1,iPos-1)
sFirstName=Mid(sUserName,iPos+1)
sUserName=sFirstName & " " & sSurname
end If
Set iPos=Nothing
End if
%>
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


