title: Script works as VBS but not HTML
body: <p>I have a script that shows a filtered list of what groups a particular AD user is a member of. It works <strong>perfectly fine</strong> as a VBS file, but when imported into either an HTA or HTML file it gives me a <em>"The search filter cannot be recognized"</em> error message when running the <em>"objRecordSet.MoveFirst"</em> line below.</p>
  
  <pre><code>Dim User
  Dim DIA
  Dim GroupList
  
  DIA = "No"
  User = "UserNic"
  
  Const ADS_SCOPE_SUBTREE = 2
  Const E_ADS_PROPERTY_NOT_FOUND  = &amp;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='" &amp; User &amp; "'" 
  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") &lt;&gt; 0 Then
                      Group = x
                      Group = Right(Group,Len(Group)-3)
                      Group = Left(Group,InStr(Group,",")-1)
                      GroupList = Group &amp; vbCrLf &amp; GroupList
                  End If
                  If InStr(x,"DIA") &lt;&gt; 0 Then DIA = "Yes"
              Next
          End if
      objRecordSet.MoveNext
  Loop
  
  WScript.Echo GroupList
  WScript.echo "DIA: " &amp; DIA
  </code></pre>
  
  <p>I also have another script which is nearly identical that <strong>does</strong> work in HTA/HTML format. This one just shows where an email account is forwarded if at all:</p>
  
  <pre><code>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='*" &amp; Hosp &amp; "' 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
  </code></pre>
  
  <p>I can't seem to find any functional differences between each script's <em>"objRecordSet.MoveFirst"</em> line. </p>
  
  <p>Please help!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Same results here. Tried an alternate chunk of code to perform the same actions - works fine as VBS but not HTA:</p>
  
  <pre><code>Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Provider=ADsDSOObject;"
  Set objCommand = CreateObject("ADODB.Command")
  objCommand.ActiveConnection = objConnection
  objCommand.CommandText = "&lt;LDAP://dc=domain,dc=com&gt;;" &amp; "(&amp;(objectCategory=Person)(mailnickname=" &amp; User &amp; "));" &amp; "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 '" &amp; User &amp; "'! 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://" &amp; objRecordSet.Fields("distinguishedname"))
              Set colGroups = objUser.Groups
              For Each objGroup in colGroups
                  Group = objGroup.CN
                  GroupList = Group &amp; vbCrLf &amp; GroupList
              Next
          End If
  End If
  
  WScript.Echo GroupList
  </code></pre>