来自:温柔一刀 时间:2000-6-20 18:41:11 ID:268738 <br>procedure ExitWindowsNT(uFlags : integer);<br> var<br> hToken : THANDLE;<br> tkp, tkDumb : TTokenPrivileges;<br> DumbInt : integer;<br> begin<br> FillChar(tkp, sizeof(tkp), 0);<br> // Get a token for this process<br> if not (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES <br> or TOKEN_QUERY, hToken)) then<br> raise Exception.create('OpenProcessToken failed with code '<br> + inttostr(GetLastError));<br><br> // Get the LUID for the Shutdown privilege<br> LookupPrivilegeValue(nil, pchar('SeShutdownPrivilege'),<br> tkp.Privileges[0].Luid);<br><br> tkp.PrivilegeCount := 1; // one privilege to set<br> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br><br> // Get the shutdown provolege for this process<br> AdjustTokenPrivileges(hToken, false, tkp, sizeof(tkDumb), tkDumb, DumbInt);<br><br> // Cannot test the return value of AdjustTokenPrivileges<br> if GetLastError <> ERROR_SUCCESS then<br> Raise Exception.create('AdjustTokenPrivileges failed with code ' <br> + inttostr(GetLastError));<br><br> // shut down the system and for all applications to close<br> if not ExitWindowsEx(uFlags, 0) then<br> Raise Exception.create('ExitWindowsEx failed with code '<br> + inttostr(GetLastError));<br> end;<br><br>调用方法:<br>ExitWindowsNT(EWX_SHUTDOWN or EWX_FORCE)<br>ExitWindowsNT(EWX_REBOOT)等等<br> <br> <br>