0

当运行下面的 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
4

1 回答 1

1

估计CurrentUser.MemberOf不是你想的那样。

您需要调试正在运行的脚本(或者如果不可能,请在其中获取一些日志,将值写入控制台或日志文件)。

你需要检查

  1. CurrentUser不是什么
  2. CurrentUser.MemberOf不是什么
  3. CurrentUser.MemberOf是一个数组
  4. CurrentUser.MemberOf是一个字符串数组
  5. 包含CurrentUser.MemberOf您期望的组。

使用TypeName函数确定变量/成员的类型

VBScript 调试器可以在这里找到http://www.microsoft.com/en-us/download/details.aspx?id=22185来调试脚本,安装调试器,然后通过传递 //x 来启动脚本cscript ( cscript //x MyScript.vbs) 或将stop关键字放在要开始调试的脚本中

希望这可以帮助。

于 2013-07-03T08:25:30.403 回答