在 NT内核的操作系统上实现系统关闭,在 NT内核的操作系统上实现系统关闭
【 tulaoshi.com - Delphi 】
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;
来源:http://www.tulaoshi.com/n/20160129/1492446.html
看过《在 NT内核的操作系统上实现系统关闭》的人还看了以下文章 更多>>