2013-07-03 42 views
0

当运行下面的VBS函数来检查当前用户是否在某个安全组中时,对于行strGroup = LCase(Join(CurrentUser.MemberOf)),我得到错误#500(变量未定义)。当定义了某个变量时,VBS函数总是返回False

我有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 

回答

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关键字

希望这会有所帮助。

+0

感谢您的回复,我会看看。看起来您的调试器链接不正确,因为无法找到页面。谢谢。 –

+0

感谢您对下载链接的反馈,我已经解决了它。 –

+0

谢谢。参加几次会议,今天晚些时候会抓住它。 –