uses
WinSvc;
function IsAdmin(Host : string = '') : Boolean;
var
H: SC_HANDLE;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
Result := True
else begin
H := OpenSCManager(PChar(Host), nil, GENERIC_READ or GENERIC_WRITE or GENERIC_EXECUTE);
Result := H <> 0;
if Result then
CloseServiceHandle(H);
end;
end;
function IsRunningWithAdminPrivs: Boolean;
begin
var
List: TStringList;
begin
List := TStringList.Create;
try
try
List.Text := 'Sample';
// Use SHGetFolder path to retreive the program files folder
// here is hardcoded for the sake of the example
List.SaveToFile('C:\program files\test.txt');
Result := True;
except
Result := False;
end;
finally
List.Free;
DeleteFile('C:\program files\test.txt');
end;
end;





پاسخ با نقل قول
