function GetShutDownPriv : Boolean;<br>const<br> PrivName : PAnsiChar = 'SeShutdownPrivilege';<br>var<br> hToken : THandle;<br> tkp, prev : TTokenPrivileges;<br> retlength : DWORD;<br>begin<br> Result := True;<br> if Win32Platform <> VER_PLATFORM_WIN32_NT then<br> Exit; // just return True if on Win9x since there's no security<br> Result := False; // return False if security token cannot be adjusted on NT<br> if not OpenProcessToken(GetCurrentProcess,<br> TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,<br> hToken) then<br> Exit;<br> if not LookupPrivilegeValue(nil, PrivName, tkp.Privileges[0].Luid) then<br> Exit;<br> prev := tkp;<br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[0].Attributes := 2;<br> AdjustTokenPrivileges(hToken, BOOL(FALSE), tkp, sizeof(prev), prev, retlength);<br> if GetLastError <> ERROR_SUCCESS then<br> Exit;<br> Result := True; // return True if SeShutdownPrivilege accepted<br>End; // GetShutDownPriv<br><br>procedure DoWindowsShutdown;<br>Begin<br> if not GetShutDownPriv then<br> begin<br> MessageBox(0, '不能关闭WIndows : 取消',<br> nil, MB_OK or MB_ICONSTOP or MB_SETFOREGROUND);<br> PostQuitMessage(0);<br> Exit;<br> end;<br> ExitWindowsEx(EWX_POWEROFF, 0); // give user chance to cancel Shutdown<br>end; // DoWindowsShutdown<br>