| 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; |