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

Retrieve Windows Username in Javascript 2

Status
Not open for further replies.

ksbigfoot

Programmer
Apr 15, 2002
856
CA
When someone is viewing your webpage, Is there a way in Javascript to retrieve the Windows UserName of that person?
 
The short answer is no. You can't - not across all browser etc.

The longer answer is... you can try this using the following (although you will get a prompt for ActiveX - and it will only work in IE for Windows):
Code:
<script type="text/javascript">
try {
  var net = new ActiveXObject("WSCRIPT.Network");
  if (net) {
    alert(net.UserName);
  } else {
    alert('Cannot get username');
  }
} catch(e) {
  // cannot create ActiveXObject
}
</script>

Let us know how you go!

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Depends on whether you are using Javascript for the web or in wsh. If you're using it in wsh
Code:
var objShell = WScript.CreateObject ("WScript.Shell");
var objEnv   = objShell.Environment ("PROCESS");
WScript.Echo (objEnv ("USERNAME"));
Basically the same as getting %USERNAME% in a DOS bat file.
 
Thanks Jeff And xwb,
I think I will just create a login screen for my web.
I would like to stay away from ActiveX controls.
Thanks for pointing me in the right direction and star to you both.
ksbigfoot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top