如何獲得所有windows使用者的SID

來源:互聯網
上載者:User
如何獲得所有windows使用者的SID Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061110113225259.html
有什麼方法可以獲得所有windows使用者的SID

訪問註冊表  
 

最好是指標形式的sid

{$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;  
      //首次調用取得Size  
      LookupAccountName(nil,   nil,   Sid,   cbSid,   ReferencedDomainName,   cbReferencedDomainName,   peUse);  
   
      if   (cbSid   =   0)   or   (cbReferencedDomainName   =   0)   then  
          Exit;//無效的使用者名稱  
   
      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;  
 

用WMI啊!!想要什麼就有什麼,從軟的到硬的。

擷取系統使用者SID  
  Select   Name,   SID   From   Win32_SystemAccount  
   
  擷取自訂使用者SID  
  Select   Name,   SID   From   Win32_UserAccount  
 

或者  
  Select   *   From   Win32_AccountSID

當然是API最好的  
  WMI是簡單,但是服務停了就不好用了~  
   
  另外註冊表的HKEY_USERS下面就有的

各位兄弟先繞我兩天,等我全都試完了再結帖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.