views:

354

answers:

3

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
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
ActiveX doesn't exactly work in Firefox.
sdwilsh
+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