Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Search Filter to get a user's guid:

Reply
 
Old 04-08-2009   #1 (permalink)
gimme_this_gimme_that


 
 

Search Filter to get a user's guid:

I'm fetching user information using ADO and have the following:

strFilter = "(&(objectCategory=person)(objectClass=user)
(distinguishedName=CN=Doe\,
John,OU=Users,OU=Someplace,OU=Somewhere,OU=Americas,DC=west,DC=msds,DC=someco,DC=com)
(mail=*)(homemdb=*))"
attributes = "givenName,sn,mail"
strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";" +
attributes + ";subtree"

This works.

If I change the attributes assignment to this:
attributes = "guid,givenName,sn,mail"

The query fails (there is no attribute named guid so I can understand
why)

Is there a way to get the GUID for this user?

Thanks.


My System SpecsSystem Spec
Old 04-09-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Search Filter to get a user's guid:


<gimme_this_gimme_that@xxxxxx> wrote in message
news:83fd2cf3-4f8b-4c8a-9cff-59e47d2ddffc@xxxxxx
Quote:

> I'm fetching user information using ADO and have the following:
>
> strFilter = "(&(objectCategory=person)(objectClass=user)
> (distinguishedName=CN=Doe\,
> John,OU=Users,OU=Someplace,OU=Somewhere,OU=Americas,DC=west,DC=msds,DC=someco,DC=com)
> (mail=*)(homemdb=*))"
> attributes = "givenName,sn,mail"
> strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";" +
> attributes + ";subtree"
>
> This works.
>
> If I change the attributes assignment to this:
> attributes = "guid,givenName,sn,mail"
>
> The query fails (there is no attribute named guid so I can understand
> why)
>
> Is there a way to get the GUID for this user?
>
> Thanks.
>
The attribute name is objectGUID. The syntac is OctetString, which is a byte
array. I use a function to convert byte arrays to hex strings. For example:
=========
Set objUser = GetObject("LDAP://cn=Jim User,ou=West,dc=MyDomain,dc=com")
arrbytGuid = objUser.objectGUID
strGuid = OctetToHexStr(arrbytGuid)
Wscript.Echo strGUID

Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (Byte Array) to a hex string.

Dim k

OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next

End Function
========
You must use a function similar to above if you retrieve the attribute value
with ADO. If you bind to the object, however, you can use the GUID property
method of the object. This method is a function that converts the value to a
hex string for you. For example:
======
Set objUser = GetObject("LDAP://cn=Jim User,ou=West,dc=MyDomain,dc=com")
strGuid = objUser.GUID
Wscript.Echo strGuid
=======
Other property methods of objects include Parent, Class, and AdsPath. Only
the later can be retrieved (and filtered on) using ADO.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Microsoft Search Filter - block or allow? General Discussion
MBR vs GUID - Can I Have Both? Vista hardware & devices
Guid and Cstr VB Script
help. Digital filter? how to de-filter? USB audio device Vista hardware & devices
Search filter "qoutes" not working (RC2) Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46