How to obtain the SID of all Windows users

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.