完整的代码<br>program ShutDown;<br><br>uses<br> Windows;<br><br>{$R *.res}<br>var<br> hToken : THandle;<br> tkp : TTokenPrivileges;<br> tkpo : TTokenPrivileges;<br> zero : DWORD;<br><br>function IsWinnt:Boolean;<br>var<br> VerInfo: _OSVERSIONINFO;<br>begin<br> VerInfo.dwOSVersionInfoSize := sizeof(VerInfo);<br> GetVersionEx(VerInfo);<br> if VerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then<br> result := true<br> else<br> result := false;<br>end;<br>begin<br> if not IsWinnt then<br> if MessageBox(0,'Shutdown?','Shutdown',MB_OKCANCEL or MB_ICONINFORMATION)<br> = idok then<br> ExitwindowsEx(EWX_REBOOT, 0);<br> zero:=0;<br> OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);<br> LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid );<br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br> AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br> if MessageBox(0,'Shutdown?','Shutdown',MB_OKCANCEL or MB_ICONINFORMATION) = idok then<br> ExitWindowsEx( EWX_FORCE or EWX_REBOOT, 0);<br>end.