//win2k
function ShutDown(uFlags: Cardinal):boolean;
const
ADJUST_PRIV = TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES;
SHTDWN_PRIV = 'SeShutdownPrivilege';
PRIV_SIZE = sizeOf(TTokenPrivileges);
var
Len: DWORD;
TokenPriv, Dummy: TTokenPrivileges;
Token: THandle;
Error:integer;
begin
error:=0;
// 设置特权
// Delphi2:
//if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, @Token) then
if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, Token) then
Error := Error or 4;
if not LookupPrivilegeValue(nil, SHTDWN_PRIV,TokenPriv.Privileges[0].Luid) then
Error := Error or 8;
TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
TokenPriv.PrivilegeCount := 1; // One privilege to set
if not AdjustTokenPrivileges(Token, false, TokenPriv, PRIV_SIZE,Dummy, Len) then
Error:=Error or 16;
ExitWindowsEx(uFlags, 0);
Result := (Error=0);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ShutDown(EWX_POWEROFF + EWX_FORCE);
end;
//win9x
强制关机 ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE,0);
强制重启 ExitWindowsEx(EWX_REBOOT OR EWX_FORCE,0);
重新登录 ExitWindowsEx(EWX_LOGOFF,0);