procedure TForm1.RebootSystem; var osVerInfo: TOSVersionInfo; rl: Cardinal; hToken: Cardinal; tkp: TOKEN_PRIVILEGES; begin if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); if GetVersionEx(osVerInfo) then case osVerInfo.dwPlatformId of VER_PLATFORM_WIN32_NT: // Windows NT/2000/XP begin OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken); if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; tkp.PrivilegeCount := 1; AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl); end; // ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE + EWX_POWEROFF, 0); //关闭计算机 ExitWindowsEx(EWX_REBOOT, $FFFF); // 重启 end; VER_PLATFORM_WIN32_WINDOWS: // Windows 95/98/98SE/Me begin // ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE + EWX_POWEROFF, 0); //关闭计算机 ExitWindowsEx(EWX_REBOOT, $FFFF); // 重启 end; end; end; end; 调用 : procedure TForm1.X1Click(Sender: TObject); begin if MessageBox(0, '你要重启计算机吗?', '警告', MB_ICONQUESTION or MB_YESNO) = idyes then begin RebootSystem; end; application.Terminate; end; //delphi/6751