依照論壇上一位前輩的代碼<br>procedure TForm1.Button2Click(Sender: TObject);<br>const<br> SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';<br>var<br> hToken : THandle;<br> tkp : TTokenPrivileges;<br> tkpo : TTokenPrivileges;<br> zero : DWORD;<br>begin<br> zero:=0;<br> if not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin<br> MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br> Exit;<br> end;<br> if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin<br> MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br> Exit;<br> end;<br><br> if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then begin<br> MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );<br> Exit;<br> end;<br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br> AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br> if Boolean( GetLastError() ) then begin<br> MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );<br> Exit;<br> end<br> else ExitWindowsEx( EWX_REBOOT or EWX_FORCE, 0 );<br> <br>end;