title: retrieving 'pre windows 2000 logon' name from LDAPMessage object in win32api C++
body: <p>I've been asked to look at windows service which retrieves data from an Active Directory tree using the win32 LDAP API and outputs JSON data to a text file. It works fine but I need to modify it so that the i get the 'pre windows 2000' login name. The service is written in c++.</p>
  
  <p>The service already successfully retrieves various other attribute strings using:</p>
  
  <pre><code>PTSTR *pszValues=ldap_get_values(pLdap,pEntry,szAttribute);
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>if (_tcscmp(szAttribute,TEXT("uUsnChanged"))==0)            // uSNChanged is an example of an attribute
  pItemInfo-&gt;uUsnChanged=_tcstoui64(pszValues[0],NULL,10);    // pItemInfo is a struct defined elsewhere to hold the results for any given entry
  </code></pre>
  
  <p>i looked on <a href="http://msdn.microsoft.com/en-us/library/ms679021(v=VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms679021(v=VS.85).aspx</a> to see if there is an attribute for 'pre windows 2000' login or something similar in the hope that I could just add this as another 'szAttribute' (to replace "uUsnChanged" in this example) and had no luck. Looking at the API i have been unable to come up with a way of getting this information.</p>
  
  <p>i found the attribute 'sAMAccountName' which i thought would provide the information needed but it only gives me the <strong>name</strong> part of the <strong>DOMAIN/name</strong> format. Typical, it's the other part i want!</p>
  
  <p>does anyone have any ideas on how to get the  <strong>'pre windows 2000'</strong> string from 'pEntry'?</p>
  
  <p>@JPBlanc We are getting the correct nETBIOSName attribute now when running it on the test server. The app works on the assumption that there is a maximum of one nETBIOSName attribute per DC. It finds it by doing the following:</p>
  
  <p>gets the default host using <code>ldap_init(NULL,0)</code></p>
  
  <p>get the 'configuration naming context' using <code>ldap_search_s(pLdap,NULL,LDAP_SCOPE_BASE,NULL,pszAttrs,FALSE,&amp;pResults);</code> passing in the connection handle as the first parameter</p>
  
  <p>retrieves the 'configurationNamingContext' attribute using <code>ldap_get_values(pLdap,pEntry,TEXT("configurationNamingContext"));</code></p>
  
  <p>concatenates "CN=Partitions," to the beggining of the string giving something like "CN=Partitions,CN=Configuration,DC=domain,DC=com,DC=au"</p>
  
  <p>it then performs a search using <code>ldap_search_s(pLdap,szPartitionNC,LDAP_SCOPE_SUBTREE,TEXT("(nETBIOSName=*)"),pszAttrs,FALSE,&amp;pResults);</code></p>
  
  <p>then it loops through the results looking for anything with a 'nETBIOSName' attribute and once it finds one it breaks out of the loop and returns the value.</p>
  
  <p>Do you know if this is sufficient to work in any AD configuration?</p>