Using ActiveX to get username

后端 未结 2 1658
闹比i
闹比i 2020-12-21 09:46

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

相关标签:
2条回答
  • 2020-12-21 10:21

    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.

    0 讨论(0)
  • 2020-12-21 10:35

    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;
    
    0 讨论(0)
提交回复
热议问题