Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the IADs interface of an active directory user?
    primarykey
    data
    text
    <p>How can i get the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa705950%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>IADs</code></a> interface of an Active Directory user - by <em>username</em>?</p> <p><strong>Note</strong>: Native code</p> <hr> <p>i am trying to write the function that can get the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa705950%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>IADs</code></a> interface of a <em>user</em> in Active Directory.</p> <p>i have the following "pseudocode" so far:</p> <pre><code>public IADs GetUserObject(string samAccountName) { IADs ads; //Get the current domain's distinguished name ("dc=stackoverflow,dc=com") AdsGetObject("LDAP://rootDSE", IADs, ref ads); String dn = ads.Get("defaultNamingContext"); //"dc=stackoverflow,dc=com" String path; //Attempt #1 to bind to a user by username path = "LDAP://sSAMAccountName="+samAccountName+",dc=stackoverflow,dc=com" AdsGetObject(path, IADs, ref ads); //invalid syntax return ads; } </code></pre> <p>The trick, that i cannot figure out, is how to bind to the user by their account name. The following variantions don't work:</p> <ul> <li><code>LDAP://sSAMAccountName=ian,dc=stackoverflow,dc=com</code></li> <li><code>LDAP://dc=stackoverflow,dc=com;(&amp;(objectCategory=user)(sAMAccountName=ian))</code></li> <li><code>&lt;LDAP://dc=stackoverflow,dc=com&gt;;(&amp;(objectCategory=user)(sAMAccountName=ian))</code></li> </ul> <blockquote> <p><strong>Edit</strong>:</p> <p>A version that <em>does</em> work, but doesn't answer my question, is:</p> <ul> <li><code>LDAP://cn=Ian Boyd,ou=Avatar Users,dc=stackoverflow,dc=com</code></li> </ul> <p>It doesn't answer my question for two reasons: </p> <ul> <li>i don't know the user's <code>CN</code> (Common-Name) (e.g. Ian Boyd), only their <code>sAMAccountName</code> (e.g. ian)</li> <li>doesn't work for users not in the <strong>Avatar Users</strong> organizational unit; and i don't know a user's OU</li> </ul> <p>Which comes from the notes i had before:</p> </blockquote> <p><strong>Note:</strong></p> <ul> <li>i don't know the name of the domain (but that's okay, i can get it at runtime)</li> <li>i don't know the name of any active directory servers</li> <li>i don't know the folder that the user is in</li> </ul> <hr> <p>tl;dr: How would you write the utility function:</p> <pre><code>public IADs GetUserObject(string samAccountName) { //TODO: ask stackoverflow } </code></pre> <p><strong>Update 2:</strong></p> <p><strong>Note</strong>:</p> <ul> <li>i already know how to query for information about a user <a href="https://stackoverflow.com/q/8564675/12597">using .NET's DirectorySearcher</a></li> <li>i already know how to query for information about a user <a href="https://stackoverflow.com/a/8575614/12597">using the Active Directory Services OLEDB provider with ADO</a> (using the SQL syntax, but not the native syntax)</li> <li>i'm now looking for code to query for information about a user <a href="https://stackoverflow.com/a/8567800/12597">using Active Directory Services COM objects</a> (hence the question about getting an <code>IADs</code> for a user)</li> </ul> <p><strong>Update 3</strong>:</p> <p>It certainly might require me to apply "<em>filters</em>", except i don't know where. The only ActiveDs interface that mentions <strong>Filter</strong> is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa705985%28v=VS.85%29.aspx" rel="nofollow noreferrer"><code>IADSContainer</code></a>, but i don't know where to get one.</p> <p>i tried randomly to get the <code>IADsContainer</code> interface from the root <code>IADs</code> interface, but "rootDSE" doesn't support <code>IADsContainer</code>:</p> <pre><code>IADs ads = AdsGetObject("LDAP://rootDSE"); IADsContainer container = (IADsContainer)ads; //interface not supported exception </code></pre> <p>i could </p> <ul> <li>ask a question on how to get the <code>IADsContainer</code> of the AD root <ul> <li>so i can ask how to recursively search active diretory <ul> <li>so i can ask how to filter using <code>IADsContainer</code> <ul> <li><a href="https://stackoverflow.com/questions/8591789/how-to-get-the-iads-interface-of-an-active-directory-user">so i can figure out how to get the IADs object of a user</a> <ul> <li><a href="https://stackoverflow.com/questions/8564675/how-to-query-activedirectory-from-native-code/8567800#8567800">so i an figure out how to query AD for user properties</a></li> </ul></li> </ul></li> </ul></li> </ul></li> </ul> <p>But keeping track of all these questions is difficult.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload