Thomas Manalil
Thomas Manalil

Reputation: 1677

Display Window username with javascript

I want to retrive login window user name and display in Browser. Can java script be used for the same?

Upvotes: 3

Views: 10671

Answers (4)

John
John

Reputation: 11

<script type="text/javascript" language="javascript">   

var objUserInfo = new ActiveXObject("WScript.network"); 
document.write(objUserInfo.ComputerName); 
document.write(objUserInfo.UserDomain); 
document.write(objUserInfo.UserName);   

</script>

Upvotes: 1

Khodor
Khodor

Reputation: 1006

I think you can using an ActiveX control (ActiveXObject("wscript.network")) example:

var ActiveX=new ActiveXObject("wscript.network");
alert(ActiveX.username);
alert(ActiveX.computername);
alert(ActiveX.userdomain);

Upvotes: 2

doro
doro

Reputation: 785

Javascript is a clientside browser language and has and should have nothing to do with the OS, so that won't work ... :)

EDIT: @thomas try to be more specific ... you want to build a plattform where users can login? then use a database where you store the users. Why do you need there windows login?

Upvotes: 0

hurikhan77
hurikhan77

Reputation: 5930

I strongly doubt that Javascript has the power to do that as that would be considered exploitable and be a security problem. Javascript runs in a sandbox and has no access to any client properties other than the browser provides through the document and window objects.

However, you could use ActiveX objects or Kerberos/NTLM authentication to pass the user name from your server-side script back to the client and thus into javascript. Both these options will only work in Internet Explorer.

If you mean the HTTPAuth login it is also the easiest way to send the username back to your client using the server-side scripts as the authentication has been required/initialized by the server side and javascript has no direct access to there.

Upvotes: 0

Related Questions