Shutdown code

xiaoxiao2021-03-14  216

procedure ShutDown; const SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; // Borland forgot this declarationvar hToken: THandle; tkp: TTokenPrivileges; tkpo: TTokenPrivileges; zero: DWORD; begin if Pos ( 'Windows NT', GetWinVersion) = 1 then // we ' ve got to do a whole buch of things begin zero: = 0; if not OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin MessageBox (0, 'Exit Error', 'OpenProcessToken () Failed', MB_OK); Exit; end; // SE_SHUTDOWN_NAME if not LookupPrivilegeValue (nil, 'SeShutdownPrivilege', tkp.Privileges [0] .Luid) then begin MessageBox (0, 'Exit Error', 'LookupPrivilegeValue () Failed', MB_OK); Exit; end ; tkp.PrivilegeCount: = 1; tkp.Privileges [0] .Attributes: = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges (hToken, False, tkp, SizeOf (TTokenPrivileges), tkpo, zero); if Boolean (GetLastError ()) then begin MessageBox (0 , 'Exit Error ',' AdjustTokenPrivileges () Failed ', MB_OK); Exit; end else ExitWindowsEx (EWX_FORCE or EWX_SHUTDOWN, 0); end // if OSVersion =' Windows NT 'else begin ExitWindowsEx (EWX_FORCE or EWX_SHUTDOWN, 0); end; end ; function GetWinVersion: String; var VersionInfo: TOSVersionInfo; OSName: String; begin VersionInfo.dwOSVersionInfoSize: = SizeOf (TOSVersionInfo); if Windows.GetVersionEx (VersionInfo) then begin with VersionInfo do begin case dwPlatformId of VER_PLATFORM_WIN32s: OSName: = 'Win32s' ;

转载请注明原文地址:https://www.9cbs.com/read-129434.html

New Post(0)