I am working a Firefox addon (which is written in JavaScript) and need to determine the Windows user currently logged on. Is there a way to do this?
+3
A:
You can use nsIEnvironment interface to get USERNAME
environmnet variable.
el.pescado
2010-06-03 18:33:21
A:
<html>
<head>
<script language="javascript">
function GetUserName()
{
var wshell = new ActiveXObject("WScript.Shell");
alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
}
</script>
</head>
<body OnLoad="GetUserName();">
</body>
</html>
carny666
2010-06-03 18:39:38
ActiveX doesn't exactly work in Firefox.
sdwilsh
2010-06-04 00:57:31
+3
A:
This does the trick on Windows:
function getUser() {
return = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USERNAME');
}
cwhiii
2010-06-03 19:09:55