0

我有一个脚本,显示特定 AD 用户所属的组的过滤列表。它作为 VBS 文件工作得非常好,但是当导入到 HTA 或 HTML 文件时,在运行下面的“objRecordSet.MoveFirst”行时,它会给我一个“无法识别搜索过滤器”错误消息。

Dim User
Dim DIA
Dim GroupList

DIA = "No"
User = "UserNic"

Const ADS_SCOPE_SUBTREE = 2
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT memberOf FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='user' And mailnickname='" & User & "'" 
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    arrMemberOf = objRecordSet.Fields("memberOf")
        if isArray(objRecordSet.Fields("memberOf")) Then
            For Each x in arrMemberOf
                If InStr(x,"GroupFilter") <> 0 Then
                    Group = x
                    Group = Right(Group,Len(Group)-3)
                    Group = Left(Group,InStr(Group,",")-1)
                    GroupList = Group & vbCrLf & GroupList
                End If
                If InStr(x,"DIA") <> 0 Then DIA = "Yes"
            Next
        End if
    objRecordSet.MoveNext
Loop

WScript.Echo GroupList
WScript.echo "DIA: " & DIA

我还有另一个几乎相同的脚本,可以在 HTA/HTML 格式下工作。这个仅显示电子邮件帐户的转发位置(如果有的话):

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT Name, altRecipient FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='user' And Name='*" & Hosp & "' And altRecipient='*'" 
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Count = 0
Do Until objRecordSet.EOF
    Name(Count) = objRecordSet.Fields("Name").Value
    Forward(Count) = objRecordSet.Fields("altRecipient").Value

    arrLines = Split(Forward(Count),",")
    search = Filter(arrLines,"CN=",True,1)
    for each x in search
        Forward(Count) = x
    Next
    Forward(Count) = Replace(Forward(Count),"CN=","")

    objRecordSet.MoveNext
    Count = Count + 1
Loop

我似乎找不到每个脚本的“objRecordSet.MoveFirst”行之间的任何功能差异。

请帮忙!

编辑:

这里的结果相同。尝试了替代代码块来执行相同的操作 - 作为 VBS 但不是 HTA 可以正常工作:

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://dc=domain,dc=com>;" & "(&(objectCategory=Person)(mailnickname=" & User & "));" & "distinguishedName,Name;subtree"
Set objRecordSet = objCommand.Execute

intCount = 0
If objRecordSet.EOF Then
    Set WshShell = CreateObject("WScript.Shell")
    message = WshShell.Popup ("Unable to find a user with the alias '" & User & "'! Please try again...",, "programname", 0 + 16)
    'Exit Sub
Else
    While NOt objRecordSet.EOF
        intCount = intCount + 1
        objRecordSet.MoveNext
    WEND
        If intCount = 1 Then
            objRecordSet.MoveFirst
            Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedname"))
            Set colGroups = objUser.Groups
            For Each objGroup in colGroups
                Group = objGroup.CN
                GroupList = Group & vbCrLf & GroupList
            Next
        End If
End If

WScript.Echo GroupList
4

2 回答 2

0

在您的 HTA 中,您是将代码放在子程序或函数中吗?

<script language = "VBScript">
Sub Window_Onload
 ##your code here##
End Sub
</script>

如果不是,则尝试将 USER 作为全局变量进行调暗可能会搞砸。

也更喜欢将 Echo 重写为类似的东西

TextOut.innerHTML = GroupList
</script>
<html><body>
<div id="TextOut"></div>
于 2012-10-02T20:44:11.120 回答
0

如果您使用的是 64 位操作系统,请尝试从命令行运行 32 位 MSHTA.exe:

C:\Windows\System32\mshta.exe C:\YOUR_PATH\yourscript.hta

我遇到了 64 位版本 ( C:\Windows\SysWOW64\mshta.exe ) 无法支持 COM/ActiveX 接口的问题。默认情况下, Windows 7 将使用 64 位版本 打开.HTA文件。

于 2012-09-13T02:24:00.690 回答