简体   繁体   English

使用javascript获取Windows用户名

[英]Get windows user name using javascript

I tried to get the windows user name in IE browser only using the below code. 我试图仅使用下面的代码在IE浏览器中获取Windows用户名。

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. 如何在其他浏览器中获取Windows用户名,如chrome,mozilla,safari。

As of today it is impossible, and will most likely be in the future as well. 截至今天,这是不可能的,也很可能在未来。

The only quirk I can come up with; 我能想到的唯一的怪癖; is to run a custom Java-Applet that checks it for you. 是运行一个自定义Java小程序,为您检查它。 However this is a passive action, and thus, you can not automatically extract it without the clients permission. 但是,这是一种被动操作,因此,如果没有客户端权限,则无法自动提取它。

I Agree with Eric comment. 我同意Eric的意见。 However try following hacks. 但是请尝试以下黑客攻击。 Most likely to work in win7 最有可能在win7中工作

In IE 在IE中

var objUserInfo = new ActiveXObject("WScript.network");
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.org/process/environment;1"]
     .getService(Components.interfaces.nsIEnvironment)
     .get('USERNAME');
}  

Source: Get OS Win 7 username Javascript 来源: 获取OS Win 7用户名Javascript

JavaScript - How to get the name of the current user JavaScript - 如何获取当前用户的名称

Get Windows username with JavaScript? 用JavaScript获取Windows用户名?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 JavaScript 中获取当前 Windows 用户的名称 - How to get the name of the current Windows user in JavaScript 如何在Google Chrome浏览器中使用javascript获取Windows用户名以获取Google Chrome扩展程序 - How to get the windows user name using javascript in google chrome browser for google chrome extension Windows用户名变量和javascript - Windows user name variable and javascript 在javascript中从用户获取变量的名称 - get name of variables from user in javascript 通过PHP或Javascript获取系统用户名 - Get system user name through PHP or Javascript 如何使用express-ntlm获得Windows用户名而无需使用NODE.js进行身份验证? - how to use express-ntlm to get windows user name without authentication using NODE.js? 如何使用节点js在vue.js中获取windows用户名 - How to get windows user name in vue.js using node js 使用node或express js从请求中获取客户端Windows登录用户名 - Get client windows login user name from request using node or express js 使用javascript获取表单名称 - Get form name using javascript 如何使用javascript获取Windows 8 Metro应用程序中mp3文件的文件名和id3标签? - How to get the file name and id3 tags of an mp3 file in a Windows 8 metro app using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM