MattsBits
MattsBits

MattsBits

Javascript Get Windows Username Within Internet Explorer  

by Matt Hawkins, 14/10/2010
Categories : JavaScript : HTML & CSS

The following script allows you to extract the username of the current Windows user within an HTML page using Javascript.

<script>
var wshshell=new ActiveXObject("wscript.shell");
var username=wshshell.ExpandEnvironmentStrings("%username%");
alert(username);
</script>


It only works within Internet Explorer so is probably only of any use within controlled environments where the browser is of a a known flavour.

The script may trigger a security warning which the user will have to accept before the username is available.

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2022