How to obtain Sid, Delphi, Windows SDK, and API of all Windows users
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061110113225259.html
How can I obtain the SID of all Windows users?
Access the Registry
Preferably a Sid in the pointer format
{$ Externalsym convertsidtostringsid}
Function convertsidtostringsid (SID: psid; stringsid: lptstr): bool; stdcall;
{$ Externalsym convertsidtostringsida}
Function convertsidtostringsida (SID: psid; stringsid: lptstr): bool; stdcall;
{$ Externalsym convertsidtostringsidw}
Function convertsidtostringsidw (SID: psid; stringsid: lptstr): bool; stdcall;
Function convertsidtostringsid; External advapi32 name 'convertsidtostringsida ';
Function convertsidtostringsida; External advapi32 name 'convertsidtostringsida ';
Function convertsidtostringsidw; External advapi32 name 'convertsidtostringsidw ';
Procedure tform1.button3click (Sender: tobject );
VaR
Cbsid: DWORD;
Sid: psid;
Peuse: sid_name_use;
Cbreferenceddomainname: DWORD;
Referenceddomainname: pchar;
Sidstr: pchar;
Begin
Cbsid: = 0;
Cbreferenceddomainname: = 0;
Sid: = nil; referenceddomainname: = nil;
// Obtain the size from the first call
Lookupaccountname (nil, nil, Sid, cbsid, referenceddomainname, cbreferenceddomainname, peuse );
If (cbsid = 0) or (cbreferenceddomainname = 0) then
Exit; // invalid user name
Getmem (SID, cbsid );
Getmem (referenceddomainname, cbreferenceddomainname );
Try
Lookupaccountname (nil, nil, Sid, cbsid, referenceddomainname, cbreferenceddomainname, peuse );
If convertsidtostringsid (SID, @ sidstr) then
Self. Caption: = referenceddomainname + '\' + sidstr;
Finally
Freememory (SID );
Freememory (referenceddomainname );
End;
End;
Use WMI !! Everything you want, from soft to hard.
Obtain system user Sid
Select name, Sid from win32_systemaccount
Get user Sid
Select name, Sid from win32_useraccount
Or
Select * From win32_accountsid
Of course it is the best API
WMI is simple, but it is not easy to use when the service is stopped ~
In addition, the HKEY_USERS in the Registry has
Let me go around for two days. Wait until I finish all the tests and complete the post.