Get Windows username in a legacy (not WebExtensions) Firefox add-on

cwhiii picture cwhiii · Jun 3, 2010 · Viewed 77.9k times · Source

I am working a Firefox add-on (which is written in JavaScript) and need to determine the Windows user currently logged on. Is there a way to do this?

Answer

cwhiii picture cwhiii · Jun 3, 2010

This does the trick on Windows:

function getUser() {
   return Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USERNAME');
}