(WIN2000关机)<br>function TForm1.SetPrivilege(sPrivilegeName: string;<br> bEnabled: Boolean): Boolean;<br><br>var<br> TPPrev,<br> TP : TTokenPrivileges;<br> Token :THandle;<br> dwRetLen : DWORD;<br>begin<br> result := False;<br> OpenProcessToken (GetCurrentProcess,<br> TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,<br> Token);<br> TP.PrivilegeCount := 1;<br> if LookupPrivilegeValue (nil, PChar (sPrivilegeName), TP.Privileges[0].LUID) then<br> begin<br> if bEnabled then<br> TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED<br> else<br> TP.Privileges[0].Attributes := 0;<br> dwRetLen := 0;<br> result := AdjustTokenPrivileges (<br> Token,<br> False,<br> TP,<br> SizeOf (TPPrev),<br> TPPrev,<br> dwRetLen);<br> end;<br> CloseHandle (Token);<br>end;<br>function Tform1.WinExit (iFlags: integer) : Boolean;<br><br>begin<br> result := true;<br> if SetPrivilege ('SeShutdownPrivilege', true) then<br> begin<br> if (not ExitWindowsEx (iFlags, 0)) then<br> begin<br> // handle errors...<br> result := False<br> end;<br> SetPrivilege ('SeShutdownPrivilege', False)<br> end<br> else<br> begin<br> // handle errors...<br> result := False<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>WinExit(EWX_POWEROFF + EWX_FORCE);<br>end;