procedure TShutDownComputer.ShutDownComputer;<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)<br> then begin<br> Exit;<br> end;<br><br> if not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br> then begin<br> Exit;<br> end;<br><br> if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid )<br> then begin<br> Exit;<br> end;<br><br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br> AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br><br> if Boolean( GetLastError() )<br> then begin<br> Exit;<br> end<br> else ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN or EWX_POWEROFF, 0);<br>end;<br>end.