当运行下面的 VBS 函数来检查当前用户是否在某个安全组中时,我收到错误 #500 (Variable is undefined) 的行strGroup = LCase(Join(CurrentUser.MemberOf))
。
我已经Option Explicit
在脚本中声明了,所以这并不奇怪。但是,当我声明变量 ( Dim strGroup
) 时,该函数停止工作并始终返回 false。
Function is_group_member(group)
Dim objNetwork
Dim objUser
Dim CurrentUser
' Set our default return value
is_group_member = False
' Directory Lookup
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
strGroup = LCase(Join(CurrentUser.MemberOf))
' Set return value to true if the user is in the selected group
If InStr(strGroup, lcase(group)) Then
is_group_member = True
End If
End Function