- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 判断是否是系统管理员身份
uses Winapi.ShellAPI,
Winapi.TlHelp32;
var
hShell32: HMODULE = 0;
var
_IsUserAnAdmin: function(): BOOL; stdcall = nil;
function CheckIsAdmin: Boolean;
begin
if Assigned(_IsUserAnAdmin) then
Result := _IsUserAnAdmin()
else
begin
Result := True;
if hShell32 = 0 then
hShell32 := LoadLibrary(shell32);
if hShell32 > HINSTANCE_ERROR then
begin
_IsUserAnAdmin := GetProcAddress(hShell32, 'IsUserAnAdmin');
if Assigned(_IsUserAnAdmin) then
Result := _IsUserAnAdmin();
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if CheckIsAdmin=true then
begin
ShowMessage('IsUserAnAdmin true');
end
else
begin
ShowMessage('IsUserAnAdmin false');
end;
end;