procedure TForm1.Button2Click(Sender: TObject);<br>var<br> VerInfo:TOSVersionInfo;<br> hToken:THANDLE;<br> tkp:TOKEN_PRIVILEGES;<br> Nothing:Cardinal;<br>begin<br> VerInfo.dwOSVersionInfoSize:=SizeOf(VerInfo);<br> GetVersionEx(VerInfo);<br> if VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT then<br> Begin<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, 0,nil, Nothing);<br> End;<br> ExitWindowsEx(EWX_POWEROFF,0);//这句就是关机<br> //ExitWindowsEx(EWX_REBOOT,0);<br>end;