Results 1 to 6 of 6

Thread: C# - need to query based on objectGUID ?

  1. #1
    bitshift Guest

    C# - need to query based on objectGUID ?

    How can I search AD if im given a objectGUID string ? Im first doing a
    search using DirectorySearcher with a "SAMAccountname=" value, which returns
    correctly. Then I get the directory entry and the objectguid. I need to
    pass this value to another part of my application, and then verify its
    existence in AD by querying the directory with it as a search filter. What
    is the filter I use to do this with ?



  2. #2
    Dean Wells \(MVP\) Guest

    Re: C# - need to query based on objectGUID ?

    Use the GUID as the base of the query like this (also note that the
    example line below describing the 'base' of the query uses angled
    brackets but is not intended to signify something you should replace; it
    is entirely literal with the obvious exception of the value for the GUID
    itself) -

    base: <GUID=EC6EEA8C-6011-43C5-9FF7-FF3D3A0A21C9>
    filter: something suitable that won't exclude the desired result set -
    your choice
    scope: same rational as a regular query - your choice

    Hope that makes sense.

    --
    Dean Wells [MVP / Directory Services]
    MSEtechnology
    [[ Please respond to the Newsgroup only regarding posts ]]
    R e m o v e t h e m a s k t o s e n d e m a i l


    "bitshift" <jobob@aol.com> wrote in message
    news:%238Y%23zIDuHHA.3368@TK2MSFTNGP02.phx.gbl...
    > How can I search AD if im given a objectGUID string ? Im first doing
    > a search using DirectorySearcher with a "SAMAccountname=" value, which
    > returns correctly. Then I get the directory entry and the objectguid.
    > I need to pass this value to another part of my application, and then
    > verify its existence in AD by querying the directory with it as a
    > search filter. What is the filter I use to do this with ?
    >




  3. #3
    bitshift Guest

    Re: C# - need to query based on objectGUID ?

    Ok, thanks. So how do I use this format when using the .Net framework
    classes such as DirectoryEntry and/or DirectorySearcher, as mentioned in
    this example article
    http://www.willasrari.com/blog/query...-c/000133.aspx

    Also, for example, could I use the static metod DirectoryEntry.Exists( ) ?
    http://msdn.microsoft.com/library/de...sts_string.asp




    "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
    news:Oq%23vtZDuHHA.3688@TK2MSFTNGP03.phx.gbl...
    > Use the GUID as the base of the query like this (also note that the
    > example line below describing the 'base' of the query uses angled brackets
    > but is not intended to signify something you should replace; it is
    > entirely literal with the obvious exception of the value for the GUID
    > itself) -
    >
    > base: <GUID=EC6EEA8C-6011-43C5-9FF7-FF3D3A0A21C9>
    > filter: something suitable that won't exclude the desired result set -
    > your choice
    > scope: same rational as a regular query - your choice
    >
    > Hope that makes sense.
    >
    > --
    > Dean Wells [MVP / Directory Services]
    > MSEtechnology
    > [[ Please respond to the Newsgroup only regarding posts ]]
    > R e m o v e t h e m a s k t o s e n d e m a i l
    >
    >
    > "bitshift" <jobob@aol.com> wrote in message
    > news:%238Y%23zIDuHHA.3368@TK2MSFTNGP02.phx.gbl...
    >> How can I search AD if im given a objectGUID string ? Im first doing a
    >> search using DirectorySearcher with a "SAMAccountname=" value, which
    >> returns correctly. Then I get the directory entry and the objectguid. I
    >> need to pass this value to another part of my application, and then
    >> verify its existence in AD by querying the directory with it as a search
    >> filter. What is the filter I use to do this with ?
    >>

    >
    >




  4. #4
    Joe Kaplan Guest

    Re: C# - need to query based on objectGUID ?

    The other way to do it if you need to specify via a filter (say to find more
    than one object at a time via GUID) is to use the standard binary encoding
    for attribute data in an LDAP filter. Essentially, you just take the binary
    version of the data and convert that into hex strings with two hex chars for
    each byte prefixed by \. Thus a GUID like this:

    B0C670E5-F05A-4748-8F4E-E8567126DD96

    is this in binary:

    E5-70-C6-B0-5A-F0-48-47-8F-4E-E8-56-71-26-DD-96

    and this in a search filter:

    (objectGUID=\E5\70\C6\B0\5A\F0\48\47\8F\4E\E8\56\71\26\DD\96)

    For a more thorough treatment of the subject including code samples for
    building those filter components in C#, you can check out the link in my sig
    for info on our book. The code samples for the book as well as a free
    chapter are on the site for download, as is a thriving support forum for
    ..NET LDAP programmers.

    Joe K.

    --
    Joe Kaplan-MS MVP Directory Services Programming
    Co-author of "The .NET Developer's Guide to Directory Services Programming"
    http://www.directoryprogramming.net
    --
    "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
    news:Oq%23vtZDuHHA.3688@TK2MSFTNGP03.phx.gbl...
    > Use the GUID as the base of the query like this (also note that the
    > example line below describing the 'base' of the query uses angled brackets
    > but is not intended to signify something you should replace; it is
    > entirely literal with the obvious exception of the value for the GUID
    > itself) -
    >
    > base: <GUID=EC6EEA8C-6011-43C5-9FF7-FF3D3A0A21C9>
    > filter: something suitable that won't exclude the desired result set -
    > your choice
    > scope: same rational as a regular query - your choice
    >
    > Hope that makes sense.
    >
    > --
    > Dean Wells [MVP / Directory Services]
    > MSEtechnology
    > [[ Please respond to the Newsgroup only regarding posts ]]
    > R e m o v e t h e m a s k t o s e n d e m a i l
    >
    >
    > "bitshift" <jobob@aol.com> wrote in message
    > news:%238Y%23zIDuHHA.3368@TK2MSFTNGP02.phx.gbl...
    >> How can I search AD if im given a objectGUID string ? Im first doing a
    >> search using DirectorySearcher with a "SAMAccountname=" value, which
    >> returns correctly. Then I get the directory entry and the objectguid. I
    >> need to pass this value to another part of my application, and then
    >> verify its existence in AD by querying the directory with it as a search
    >> filter. What is the filter I use to do this with ?
    >>

    >
    >




  5. #5
    Dean Wells \(MVP\) Guest

    Re: C# - need to query based on objectGUID ?

    This JoeK's area of expertise, I'll defer to him on how best to proceed.

    G'luck!

    --
    Dean Wells [MVP / Directory Services]
    MSEtechnology
    [[ Please respond to the Newsgroup only regarding posts ]]
    R e m o v e t h e m a s k t o s e n d e m a i l


    "bitshift" <jobob@aol.com> wrote in message
    news:O00KkhDuHHA.1212@TK2MSFTNGP05.phx.gbl...
    > Ok, thanks. So how do I use this format when using the .Net framework
    > classes such as DirectoryEntry and/or DirectorySearcher, as mentioned
    > in this example article
    > http://www.willasrari.com/blog/query...-c/000133.aspx
    >
    > Also, for example, could I use the static metod
    > DirectoryEntry.Exists( ) ?
    > http://msdn.microsoft.com/library/de...sts_string.asp
    >
    >
    >
    >
    > "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
    > news:Oq%23vtZDuHHA.3688@TK2MSFTNGP03.phx.gbl...
    >> Use the GUID as the base of the query like this (also note that the
    >> example line below describing the 'base' of the query uses angled
    >> brackets but is not intended to signify something you should replace;
    >> it is entirely literal with the obvious exception of the value for
    >> the GUID itself) -
    >>
    >> base: <GUID=EC6EEA8C-6011-43C5-9FF7-FF3D3A0A21C9>
    >> filter: something suitable that won't exclude the desired result
    >> set - your choice
    >> scope: same rational as a regular query - your choice
    >>
    >> Hope that makes sense.
    >>
    >> --
    >> Dean Wells [MVP / Directory Services]
    >> MSEtechnology
    >> [[ Please respond to the Newsgroup only regarding posts ]]
    >> R e m o v e t h e m a s k t o s e n d e m a i l
    >>
    >>
    >> "bitshift" <jobob@aol.com> wrote in message
    >> news:%238Y%23zIDuHHA.3368@TK2MSFTNGP02.phx.gbl...
    >>> How can I search AD if im given a objectGUID string ? Im first
    >>> doing a search using DirectorySearcher with a "SAMAccountname="
    >>> value, which returns correctly. Then I get the directory entry and
    >>> the objectguid. I need to pass this value to another part of my
    >>> application, and then verify its existence in AD by querying the
    >>> directory with it as a search filter. What is the filter I use to
    >>> do this with ?
    >>>

    >>
    >>

    >
    >




  6. #6
    Joe Kaplan Guest

    Re: C# - need to query based on objectGUID ?

    The Exists method has some serious downsides in that it only works if you
    aren't supplying credentials or auth flags, but it can be used. In general,
    the type of DN that Dean referred to can be used in place of an standard
    LDAP style DN. For example, if the user is this DN and GUID:

    CN=someone,CN=users,DC=domain,DC=com
    6FE5DA35-4081-437B-8213-B648AD4B7B67

    You could build a path like this:
    LDAP://CN=someone,CN=users,DC=domain,DC=com
    or
    LDAP://<GUID=6FE5DA35-4081-437B-8213-B648AD4B7B67>

    Thus, in any place you need to use an ADSI path (DirectoryEntry constructor,
    Exists method, etc.) you can use this type of syntax. You can also add the
    optional server/domain part to the path as needed.

    There is a ton more info on this stuff in ch 3 of my book as previously
    suggested, including more information on the "other" DN syntaxes besides the
    standard LDAP style and GUID.

    Joe K.

    --
    Joe Kaplan-MS MVP Directory Services Programming
    Co-author of "The .NET Developer's Guide to Directory Services Programming"
    http://www.directoryprogramming.net
    --
    "bitshift" <jobob@aol.com> wrote in message
    news:O00KkhDuHHA.1212@TK2MSFTNGP05.phx.gbl...
    > Ok, thanks. So how do I use this format when using the .Net framework
    > classes such as DirectoryEntry and/or DirectorySearcher, as mentioned in
    > this example article
    >
    >
    > Also, for example, could I use the static metod DirectoryEntry.Exists( ) ?
    > http://msdn.microsoft.com/library/de...sts_string.asp
    >
    >
    >
    >
    > "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
    > news:Oq%23vtZDuHHA.3688@TK2MSFTNGP03.phx.gbl...
    >> Use the GUID as the base of the query like this (also note that the
    >> example line below describing the 'base' of the query uses angled
    >> brackets but is not intended to signify something you should replace; it
    >> is entirely literal with the obvious exception of the value for the GUID
    >> itself) -
    >>
    >> base: <GUID=EC6EEA8C-6011-43C5-9FF7-FF3D3A0A21C9>
    >> filter: something suitable that won't exclude the desired result set -
    >> your choice
    >> scope: same rational as a regular query - your choice
    >>
    >> Hope that makes sense.
    >>
    >> --
    >> Dean Wells [MVP / Directory Services]
    >> MSEtechnology
    >> [[ Please respond to the Newsgroup only regarding posts ]]
    >> R e m o v e t h e m a s k t o s e n d e m a i l
    >>
    >>
    >> "bitshift" <jobob@aol.com> wrote in message
    >> news:%238Y%23zIDuHHA.3368@TK2MSFTNGP02.phx.gbl...
    >>> How can I search AD if im given a objectGUID string ? Im first doing a
    >>> search using DirectorySearcher with a "SAMAccountname=" value, which
    >>> returns correctly. Then I get the directory entry and the objectguid. I
    >>> need to pass this value to another part of my application, and then
    >>> verify its existence in AD by querying the directory with it as a search
    >>> filter. What is the filter I use to do this with ?
    >>>

    >>
    >>

    >
    >




Similar Threads

  1. Want to make query dependent on another query.
    By MACE in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 05:22 PM
  2. Replies: 3
    Last Post: 16-11-2009, 12:29 PM
  3. How to Create view based on table-join query
    By Preetish in forum Windows Software
    Replies: 3
    Last Post: 12-08-2009, 01:44 PM
  4. Turn on MySQL query cache to speed up query performance
    By DMA2Superman in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 10:26 AM
  5. Replies: 1
    Last Post: 07-02-2008, 10:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,047,414.18619 seconds with 17 queries