Error on ActiveXObject("ADSystemInfo")
I have this line on my JavaScript
var objSysInfo=new ActiveXObject("ADSystemInfo");
var objUser=GetObject("LDAP://" + objSysInfo.UserName);
alert(objUser.displayName);
When I am logged in as an admin everything works fine, but if I am logged in as a non-admin account it starts to give exception on
var objSysInfo=new ActiveXObject("ADSystemInfo");
what seems to be the problem here and how will I solve it? Are there any other alternatives to get the User Info from javascript, I just want to get the display name? (I know this wont work on FF and Chrome)
BTW this is the error I Get "a开发者_开发问答utomation server can't create object active x"
The error indicates that the browser security settings of the current user probably don't permit the instantiation of that particular ActiveX control. Unless you can change the browser security settings of the user, there's really nothing you can do about it programmatically (using JavaScript).
You don't get the same error as an admin user probably because of more lax security settings.
Try playing around with the ActiveX security settings in Internet Options and see if you can get it to work with the non-admin user. Maybe the solution for your end users is to provide documentation on how to change the ActiveX security settings.
I know that this question was asked a few years ago. However, i am answering just in case someone might need this information:
You might want to use something more like this:
**JavaScript**
var wshshell = new ActiveXObject("wscript.shell");
var userName = wshshell.ExpandEnvironmentStrings("%username%");
alert(userName);
**VBScript**
Set ObjSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Dim userName = objUser.SAMAccountName
'In this case, username will be populated with whatever the AD requires for
'authentication when logging in
Maybe that'll work for you??
精彩评论