VBScript returning 0 rows when ADSIEdit returns correct number of rows
I've been banging my head against this for the last two days or so, and without much success - regardless what I try. When I run a query to retrieve share volumes which ends with a specific ending, I get it to work properly in ADSIEdit - but not in my VBScript. Really odd, as I'm using exactly the same query.
The ADSIEdit query is configured like so:
- Name: Test
- Root of Search: DC=ad,DC=server,DC=com
- Query String: (&(objectCategory=volume)(objectClass=volume)(cn=K_*))
Query Scope: Subtree search.
- Search results: 11 records where the cn starts with K_
- VbScript results: 1 record (!?!?)
If I change the query string to (last part) (uNCName=*\5cOst-gro)) instead, which is what I really want (the first query string I gave was for testing purposes), in ADSIEdit I get 7 rows returned - in my VBScript none!
Here's my (current) VBScript code:
Set objDomain = getObject("LDAP://RootDSE")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
strDNSDomain = objDomain.Get("defaultNamingContext")
objCommand.CommandText = "Select Name, uNCName, ManagedBy from "_
& "'LDAP://DC=ad,DC=server,DC=com'" _
& " where objectClass='volume' and uNCName = '*\5cOst-gro'"
'The below is not working either!
'objCommand.CommandText = "<LDAP://DC=ad,DC=server,DC=com>;"_
' & "(&(objectCategory=volume)(objectClass=volume)(uNCName=*\5cOst-gro));"_
' & "name,uNCName;subtree"
Set objRecordSet = objCommand.Execute( , , adCmdTableDirect)
avarGetRowsArray = objRecordset.GetRows(intNumRows, BkMrk) ' returns 0 too
objRecordSet.MoveFirst ' Doesn't help
If objRecordSet.Supports(adApproxPosition)=True Then
nrRecords=objRecordSet.RecordCount
End If
if not objRecordSet.EOF Then
do While Not objRecordSet.EOF
MsgBox "Match found! " & objRecordSet.Fields("name").Value, vbOKOnly, "Match found"
objRecordSet.MoveNext
Loop
Else
MsgBox "No matches found. " & UBound(avarGetRowsArray), vbOKOnly, "No matches!"
end If
Hoping someone can help. I've read countless topics on it but failed with each and every one :(
EDIT: I've think I've nailed it down to a trust/permission issue. When I run adfind (or dsquery) on the AD machine, it returns the correct 开发者_StackOverflow社区number of rows. However, if I run it on the client machine, it returns the wrong amount of rows. The question now is, how do I do to solve it?
SERVER:
D:\Tests>adfind -c -f "(&(objectCategory=volume)(objectClass=volume)(uNCName=*\5
cOst-gro))"
AdFind V01.45.00cpp Joe Richards (joe@joeware.net) March 2011
Using server: ad.server.com:389
Directory: Windows Server 2003
Base DN: DC=ad,DC=server,DC=com
7 Objects returned
D:\Tests>
CLIENT:
C:\tests>adfind -c -f "(&(objectCategory=volume)(objectClass=volume)(uNCName=*\5
cOst-gro))"
AdFind V01.45.00cpp Joe Richards (joe@joeware.net) March 2011
Using server: ad.server.com:389
Directory: Windows Server 2003
Base DN: DC= DC=ad,DC=server,DC=com
0 Objects returned
C:\tests>adfind -c -f "(&(objectCategory=volume)(objectClass=volume)(cn=K_*))"
AdFind V01.45.00cpp Joe Richards (joe@joeware.net) March 2011
Using server: ad.server.com:389
Directory: Windows Server 2003
Base DN: DC= DC=ad,DC=server,DC=com
1 Objects returned
@exodus: your escaping sign is the error. you have to use "\5C" (upper case) if you want to search for a backslash. hier is a link for more details: http://www.rlmueller.net/CharactersEscaped.htm
精彩评论