uses
Windows;
function GetSysTypes: Boolean; // & 獲取操作系統類型 &
function SetPrivilege(sPrivilegeName: AnsiString; bEnable: Boolean): Boolean; // & 設置權限 &
procedure ExitWin32Sys(iFlags: Integer); // & 執行注銷、退出或重啟系統的操作 &
implementation
function GetSysTypes: Boolean;
var
Ver: TOSVersionInfo;
begin
Result := False;
Ver.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
if GetVersionEx(Ver) then
if Ver.dwPlatformId = VER_PLATFORM_WIN32_Windows then
Result := True
else
Result := False;
end;
function SetPrivilege(sPrivilegeName: AnsiString; bEnable: Boolean): Boolean;
var
TPPrev, TP: TTokenPrivileges;
Token : THandle;
dwRetLen : DWord;
begin
Result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, Token);
TP.PrivilegeCount := 1;
if LookupPrivilegeValue(nil,PAnsiChar(sPrivilegeName),TP.Privileges[0].LUID) then
begin
if bEnable then
TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
TP.Privileges[0].Attributes := 0;
dwRetLen := 0;
Result := AdjustTokenPrivileges(Token, False, TP, SizeOf(TPPrev), TPPrev, dwRetLen);
end;
CloseHandle(Token);
end;
procedure ExitWin32Sys(iFlags: Integer);
begin
if GetSysTypes then
ExitWindowsEx(iFlags,0)
else
if SetPrivilege('SeShutdownPrivilege',True) then
if not ExitWindowsEx(iFlags,0) then
SetPrivilege('SeShutdownPrivilege',False);
end;