To: kingdeezj<br><br>当然,前提是你已经获得了权限,例如:<br><br>procedure AdjustToken();<br>var<br> hdlProcessHandle : Cardinal;<br> hdlTokenHandle : Cardinal;<br> tmpLuid : Int64;<br> tkp : TOKEN_PRIVILEGES;<br> tkpNewButIgnored : TOKEN_PRIVILEGES;<br> lBufferNeeded : Cardinal;<br> Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;<br>begin<br> hdlProcessHandle := GetCurrentProcess;<br> OpenProcessToken(hdlProcessHandle,<br> (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),<br> hdlTokenHandle);<br> // Get the LUID for shutdown privilege.<br> LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);<br> Privilege[0].Luid := tmpLuid;<br> Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;<br> tkp.PrivilegeCount := 1; // One privilege to set<br> tkp.Privileges[0] := Privilege[0];<br> // Enable the shutdown privilege in the access token of this process.<br> AdjustTokenPrivileges(hdlTokenHandle,False,tkp,Sizeof(tkpNewButIgnored),<br> tkpNewButIgnored,lBufferNeeded);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> AdjustToken;<br> ExitWindowsEx(EWX_LOGOFF , 0);<br> //ExitWindowsEx(EWX_SHUTDOWN, 0);<br> //ExitWindowsEx(EWX_REBOOT , 0);<br> //ExitWindowsEx(EWX_FORCE , 0);<br> //ExitWindowsEx(EWX_POWEROFF, 0);<br> //ExitWindowsEx(EWX_FORCEIFHUNG , 0);<br>end;