問題描述
我正在處理一個用經典 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;
這篇關于使用 ActiveX 獲取用戶名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!