判断当前用户是否为超级用户[Win2000]

时间:2010-03-02 18:02:05  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:>beginResult := False;bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,hAccessToken);if not bSuccess thenbeginif GetLastError = ERROR_NO_TOKEN thenbSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,hAccessToken);end;...
  正文:function IsAdmin: Boolean;
var

hAccessToken: THandle;

ptgGrouphotoshop/ target=_blank class=infotextkey>ps: PTokenGroups;

dwInfoBufferSize: Dword;

psidAdministrators: PSID;

x: Integer;

bSuccess: BOOL;

begin

Result := False;

bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,

hAccessToken);

if not bSuccess then

begin

if GetLastError = ERROR_NO_TOKEN then

bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,

hAccessToken);

end;

if bSuccess then

begin

GetMem(ptgGroups, 1024);

bSuccess := GetTokenInformation(hAccessToken, TokenGroups,

ptgGroups, 1024, dwInfoBufferSize);

CloseHandle(hAccessToken);

if bSuccess then

begin

AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,

SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,

0, 0, 0, 0, 0, 0, psidAdministrators);

{$R-}

for x := 0 to ptgGroups.GroupCount - 1 do

if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then

begin

Result := True;

Break;

end;

{$R+}

FreeSid(psidAdministrators);

end;

FreeMem(ptgGroups);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if isAdmin then

begin

ShowMessage('Logged in as Administrator');

end;

"判断当前用户是否为超级用户[Win2000]"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12989.html


关键字:

关于《判断当前用户是否为超级用户[Win2000]》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td