function SetPrivilege(aPrivilegeName : string;<br> aEnabled : boolean ): boolean; <br>var <br> TPPrev, <br> TP : TTokenPrivileges; <br> Token : THandle;<br> dwRetLen : DWord; <br>begin <br> Result := False; <br> OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES<br> or TOKEN_QUERY, Token );<br><br> TP.PrivilegeCount := 1; <br> if( LookupPrivilegeValue(nil, PChar( aPrivilegeName ), <br> TP.Privileges[ 0 ].LUID ) ) then<br> begin <br> if( aEnabled )then<br> TP.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED <br> else<br> TP.Privileges[0].Attributes:= 0; <br><br> dwRetLen := 0;<br> Result := AdjustTokenPrivileges(Token,False,TP, <br> SizeOf( TPPrev ), <br> TPPrev,dwRetLen ); <br> end;<br><br> CloseHandle( Token ); <br>end; <br><br><br>function WinExit( iFlags : integer ) : boolean;<br>// possible Flags: <br>// EWX_LOGOFF<br>// EWX_REBOOT<br>// EWX_SHUTDOWN<br>begin<br> Result := True;<br> if( SetPrivilege( 'SeShutdownPrivilege', true ) ) then<br> begin<br> if( not ExitWindowsEx( iFlags, 0 ) )then<br> begin<br> Result := False;<br> end;<br> SetPrivilege( 'SeShutdownPrivilege', False )<br> end<br> else<br> begin<br> Result := False;<br> end;<br>end;<br>