Hi, I've maid a program with Delphi 2005 to read out every user of a domain. Now I want to read out the SID of every domain user. I lookup the SID of the user with the function LookupAccountName(). This work fine, but there is a problem. If there is an local user which have the same name as an domain user (like Administrator) I receive the SID of the local user. I though I can find a solution, when call the function LookupAccountName() with the domain controller name as parameter. But how do I get the domain-controller name? thank,
>I've maid a program with Delphi 2005 to read out every user of a >domain. Now I want to read out the SID of every domain user. If you're using the .NET personality of D2005, and if you're in a AD environment, this is pretty easy - use System.DirectoryServices. using System.DirectoryServices; var sDefNamingContext : string; oRootDSE, oTopDomain : DirectoryEntry; dsFindUsers : DirectorySearcher; oResult : SearchResult; begin // grab the default naming context from RootDSE oRootDSE := DirectoryEntry.Create('LDAP://RootDSE'); sDefNamingContext := oRootDSE.Properties['defaultNamingContext'].Value.ToString(); // bind to the default naming context oTopDomain := DirectoryEntry.Create('LDAP://' + sDefNamingContext); // create the dir searcher dsFindUsers := DirectorySearcher.Create(oTopDomain); // you want users dsFindUsers.Filter := '(objectCategory=Person)'; // you want to retrieve name and sid dsFindUsers.PropertiesToLoad.Add('name'); dsFindUsers.PropertiesToLoad.Add('objectSid'); // try to find all users for oResult in dsFindUsers.FindAll() do begin Console.WriteLine(oResult.Properties['name'][0].ToString()); Console.WriteLine(oResult.Properties['objectSid'][0].ToString()); end; end; HTH Marc
Unfortunately I don't use .NET-Programming in Delphi. I use standard Delphi. Is there a way to use your code anyway?
>Unfortunately I don't use .NET-Programming in Delphi. >I use standard Delphi. >Is there a way to use your code anyway? No, in Win32 Delphi, it's going to be VERY MESSY - sorry. You would have to look at the IDirectorySearch interface and deal with that - not a pleasant thought, really....... Marc ________________________________________________________________ Marc Scheuner ** mscheuner -at- mvps.org ** http://adsi.mvps.org Microsoft MVP for Directory Services Programming http://www.dirteam.com/blogs/mscheuner/default.aspx http://groups.yahoo.com/group/ADSIANDDirectoryServices/