Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 9 Sep 2005 05:40:48 -0700,    group: microsoft.public.platformsdk.adsi        back       


read out sid of every user of a domain   
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,
date: 9 Sep 2005 05:40:48 -0700   author:   Robin

Re: read out sid of every user of a domain   
>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
date: Sat, 10 Sep 2005 11:43:04 +0200   author:   Marc Scheuner [MVP ADSI]

Re: read out sid of every user of a domain   
Unfortunately I don't use .NET-Programming in Delphi.
I use standard Delphi.

Is there a way to use your code anyway?
date: 12 Sep 2005 02:56:26 -0700   author:   Robin

Re: read out sid of every user of a domain   
>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/
date: Tue, 13 Sep 2005 07:59:53 +0200   author:   Marc Scheuner [MVP ADSI]

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us