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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I Get Windows logon name with javascript?

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
US
Hi,
On Windows (2000 or newer) using IE6+, is there a way in javascript--without calling some ActiveX--to get the windows network login name on the client computer? If so, how would I do that.

If not, is there an ActiveX call that would do this? This is for an Intra-net web application, so I have some control over the clients, but we still want to avoid opening ActiveX even to intra-net zones.
Thanks,
--Jim
 
this worked for me...

Code:
<%
Dim sFullUser
Dim iPos
Dim sDomain
Dim sUser
Dim objUser

     sFullUser = trim(Request.ServerVariables ("LOGON_USER"))
    iPos = InStr(sFullUser, "\")
    sDomain = Left(sFullUser, iPos - 1)
    sUser = Mid(sFullUser, iPos + 1)
   
    Set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)
%>

<html>
<body>
This is your name: <%=objUser.FullName%>
</body>
</html>

which i got from here.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Version using ActiveXObject.
[tt]
var wshnetwork=new ActiveXObject("wscript.network");
var suser=wshnetwork.username;
var sdomain=wshnetwork.userdomain;
[/tt]
 
Thanks,
The ActiveX works, but I will have to set a policy to allow 'not marked as safe' activeX controls, which will have to do.

The ASP thing would be ok, but I'd tried that and it returns a blank--I'm guessing that's because the browser can't fetch the "Logon_Name" unless the browser security allows it? Anyone know if this is true? It would have to be something other than the ActiveX settings that would allow this, because after I set the 'Allow Activex not marked safe', the ASP Servervariable still returned a blank. I guess I can see why, otherwise anyone surfing the internet would be giving out network usernames to any site that wanted it.
--Jim
 
If you prefer server-side variable approach, you need to set the server, rather than anything on the client, so as to exige integrated authentication and to disallow anonymous access.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top