使用 ActiveX 获取用户名
我正在处理一个用经典 ASP 编写的旧 Intranet 站点.我正在尝试检索他们登录机器时使用的用户名.每个用户都登录到 AD,但我无法从服务器检索它,因为 Intranet 站点不使用 AD.
I'm working with an old intranet site written in classic ASP. I'm trying to retrieve their username they logged into their machine with. Each user is logged into AD, but I can't retrieve it from the server since the intranet site does not use AD.
有人告诉我可以使用 ActiveX 来检索它.我做了一些研究,发现了以下代码(javascript):
I was told I could use ActiveX in order to retrieve it. I did some research and I found the following code (javascript):
var wshshell = new ActiveXObject("WScript.shell");
var username = wshshell.ExpandEnvironmentalStrings("%username%");
目前我使用的是 IE8,第一行出现自动化服务器无法创建对象"错误.
Currently I'm using IE8 and I get an "Automation server can't create object" error on that first line.
1) 任何想法为什么我会收到错误?
1) Any ideas why I'm getting the error?
2) 鉴于我的局限性,有没有更好的方法来做到这一点?
2) Is there a better way to be doing this given my limitations?
推荐答案
如果这是在客户端完成的,那么您必须让用户将站点添加到受信任的站点区域并将安全级别设置为最低.第 1 行应该在服务器端工作,但我认为第 2 行不正确.
If this is done client-side, then you must have the user add the site to the Trusted Sites zone and set the security level to the lowest. Line 1 should work server-side, but I don't think line 2 is right.
试试这个
var net = new ActiveXObject ( "WScript.NetWork" );
var username = net.UserName;
相关文章