最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Get windows user name using javascript - Stack Overflow

programmeradmin4浏览0评论

I tried to get the windows user name in IE browser only using the below code.

function GetUserName() 
{ 
    var wshell = new ActiveXObject("WScript.Shell"); 
    alert(wshell.ExpandEnvironmentStrings("%USERNAME%")); 
} 

How to get the windows username in other browsers like chrome, mozilla, safari.

I tried to get the windows user name in IE browser only using the below code.

function GetUserName() 
{ 
    var wshell = new ActiveXObject("WScript.Shell"); 
    alert(wshell.ExpandEnvironmentStrings("%USERNAME%")); 
} 

How to get the windows username in other browsers like chrome, mozilla, safari.

Share Improve this question asked Mar 24, 2015 at 12:04 Lakshmi Lakshmi 1752 gold badges4 silver badges16 bronze badges 1
  • 6 Uhm. I'm surprised you can do this in IE! This is incredibly intrusive and shouldn't be done. I'm pretty sure that privacy conscious browsers like Chrome and Safari dont do that. They also dont support ActiveX. Thank god. – somethinghere Commented Mar 24, 2015 at 12:06
Add a ment  | 

2 Answers 2

Reset to default 4

I Agree with Eric ment. However try following hacks. Most likely to work in win7

In IE

var objUserInfo = new ActiveXObject("WScriptwork");
document.write(objUserInfo.ComputerName+"<br>"); 
document.write(objUserInfo.UserDomain+"<br>"); 
document.write(objUserInfo.UserName+"<br>");  
var uname =  objUserInfo.UserName;
alert(uname);

Firefox:

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

Source: Get OS Win 7 username Javascript

JavaScript - How to get the name of the current user

Get Windows username with JavaScript?

As of today it is impossible, and will most likely be in the future as well.

The only quirk I can e up with; is to run a custom Java-Applet that checks it for you. However this is a passive action, and thus, you can not automatically extract it without the clients permission.

发布评论

评论列表(0)

  1. 暂无评论