全部博文(788)
分类:
2009-04-08 09:22:44
访问注册表
最好是指针形式的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下面就有的
各位兄弟先绕我两天,等我全都试完了再结帖