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!

User Name

Status
Not open for further replies.

harwooddale

Programmer
Feb 7, 2003
40
GB
Hi,
I would like to display the current operating system username in Internet explorer. Is this possible using Vbscript?
I have managed this using an API call to advapi32.dll in VBA code but it doesn't seem to work in a web page.

Any help appreciated.
 
Hi James

Try this:

<%= Request.ServerVariables(&quot;LOGON_USER&quot;) %>

Digga

Sharing Knowledge Saves Valuable Time!
 
my current code looks like this
<SCRIPT TYPE=&quot;text/VBScript&quot;>
<!--
Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias &quot;GetUserNameA&quot; (ByVal lpBuffer As String, nsize As Long) As Long
'function to retrieve username
Public Function getcurrentusername() As String

Dim strtext As String * 255
Dim strName As String
Dim lnglength As Long
lnglength = 255

strName = GetUserName(strtext, lnglength)

strName = Left(strtext, lnglength - 1)
If lnglength = 255 Then
getcurrentusername = &quot;not logged in&quot;
Else
getcurrentusername = strName
End If

End Function
//-->
</SCRIPT>

where would i put this line?
<%= Request.ServerVariables(&quot;LOGON_USER&quot;) %>

Thanks.
 
In VBS you can't declare external DLL, nor use typed variables. Try this:
Code:
Public Function getcurrentusername()
    getcurrentusername = <%= Request.ServerVariables(&quot;LOGON_USER&quot;) %> 
End Function

Hope This Help
PH.
 
Right,
I have created some code to get username, computername and domain.
The only problem is that it comes up with a message box from internet explorer saying that activex controls are unsafe and do i want to continue.
Is there any way that I can auto accept this message as i always want to say yes?
The code is as follows:
<SCRIPT TYPE=&quot;text/VBScript&quot;>
<!--
Dim objNet
On Error Resume Next
Set objNet = CreateObject(&quot;WScript.NetWork&quot;)
Dim strInfo
strInfo = &quot;UserName is &quot; & objNet.UserName & vbCRLF & _
&quot;ComputerName is &quot; & objNet.ComputerName & vbCRLF & _
&quot;DomainName is &quot; & objNet.UserDomain
MsgBox strInfo
//-->
</SCRIPT>
 
This is a client-side security policy issue (IE's option)

Hope This Help
PH.
 
PHV and Digga have the best answer.

<%= Request.ServerVariables(&quot;LOGON_USER&quot;) %>

I have been using this for years and it never fails. Excellent for adding security and identifying users
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top