javascript - Using ActiveX to get username - Stack Overflow

I'm working with an old intranet site written in classic ASP.I'm trying to retrieve their u

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.

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%");

Currently I'm using IE8 and I get an "Automation server can't create object" error on that first line.

1) Any ideas why I'm getting the error?

2) Is there a better way to be doing this given my limitations?

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.

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%");

Currently I'm using IE8 and I get an "Automation server can't create object" error on that first line.

1) Any ideas why I'm getting the error?

2) Is there a better way to be doing this given my limitations?

Share Improve this question edited Oct 23, 2009 at 3:15 Metro Smurf 38.4k20 gold badges115 silver badges146 bronze badges asked Jul 24, 2009 at 17:56 VinPepeVinPepe 5611 gold badge4 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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.

Try this

var net = new ActiveXObject ( "WScript.NetWork" );
var username = net.UserName;

Basically, its impossible to retrieve client's Windows machine information using Javascript. Because its scope is upto browser only.

For doing so you need to create COM object or say an Activex object, and using ASPX page you need to deploy it on Client's system at the very first time your page is accessed from a browser.

Now, ActiveX object has a featured to interact using javascript. You have to access the COM object or the class and function of the COM, which further interact with the system classes to get the system Information. i.e logged in client's windows user information.

var net = new ActiveXObject ( "WScript.NetWork" );
var username = net.UserName;

Above code is also initializing a COM object, if it is not deployed to your client system this script won't work.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743763632a4503090.html

相关推荐

  • javascript - Using ActiveX to get username - Stack Overflow

    I'm working with an old intranet site written in classic ASP.I'm trying to retrieve their u

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信