我在VBScript中遇到一个问题,我的登录脚本只看到用户直接进入的组,而不是用户间接进入的嵌套组。例如,如果User1在GroupA中,而GroupA在GroupB中,脚本无法识别User1也是GroupB的成员。
Set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName
strUserDomain = objNetwork.UserDomain
Set objUser = GetObject("WinNT://" & strUserDomain & "/" & strUserName & ",user"
strGroupList = ""
For Each objGroup In objUser.Groups
strGroupList = strGroupList & "[" + objGroup.Name & "] "
GetNested(objGroup)
Next
GetNested定义如下(通过略微修改从Hey,Scripting Guy文章获得此内容)
Function GetNested(objGroup)
On Error Resume Next
colMembers = objGroup.GetEx("memberOf")
For Each strMember in colMembers
strPath = "LDAP://" & strMember
Set objNestedGroup = GetObject(strPath)
strGroupList = strGroupList & "[" + objNestedGroup.Name & "] "
GetNested(objNestedGroup)
Next
End Function
感谢任何帮助。
答案 0 :(得分:0)
找到我自己的答案。这里的问题似乎源于WinNT和LDAP的混合。
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
使用LDAP创建objUser工作。希望这也有助于其他人