如何强制重启Windows 98和2000?(200分)

  • 主题发起人 主题发起人 yangyang2008
  • 开始时间 开始时间
Y

yangyang2008

Unregistered / Unconfirmed
GUEST, unregistred user!
1、能够强制关闭所有正在运行的程序!<br>2、重新启动时不需要人为干预,比如点击某个按钮和输入密码等。
 
function LoadLibrary16(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;<br>procedure FreeLibrary16(HInstance: THandle); stdcall; external kernel32 index 36;<br>function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;<br>procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';<br>var<br>&nbsp; hInst16: THandle;<br>&nbsp; GFSR: Pointer;<br>function RestartWindows: WordBool;<br>var<br>&nbsp; ThunkTrash: array[0..$20] of Word;<br>&nbsp; dw: DWord;<br>&nbsp; w: Word;<br>begin<br>&nbsp; if Win32Platform = VER_PLATFORM_WIN32_NT then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; ThunkTrash[0] := hInst16; //Prevent the optimizer from getting rid of ThunkTrash<br>&nbsp; hInst16 := LoadLibrary16('user.exe');<br>&nbsp; if hInst16 &lt; 32 then<br>&nbsp; &nbsp; raise Exception.Create('Cannot load USER.EXE');<br>&nbsp; FreeLibrary16(hInst16); //Decrement the usage count. This doesn't really free the library, since USER.EXE is always loaded<br>&nbsp; GFSR := GetProcAddress16(hInst16, 'ExitWindows'); //Get the function pointer for the 16-bit function in USER.EXE<br>&nbsp; if GFSR = nil then<br>&nbsp; &nbsp; raise Exception.Create('Cannot get address of ExitWindows');<br>&nbsp; dw := EW_RestartWindows;<br>&nbsp; w &nbsp;:= 0;<br>&nbsp; asm &nbsp;//Thunk down to USER.EXE<br>&nbsp; &nbsp; push dw &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { push arguments }<br>&nbsp; &nbsp; push w<br>&nbsp; &nbsp; mov edx, GFSR &nbsp; &nbsp; { load 16-bit procedure pointer }<br>&nbsp; &nbsp; call QT_Thunk &nbsp; &nbsp; { call thunk }<br>&nbsp; &nbsp; mov Result, ax &nbsp; &nbsp;{ save the result }<br>&nbsp; end;<br>end;<br>{$StackFrames Off}
 
{-----------------------------------------------------------------------------<br>&nbsp; 函数名称: ShutDown<br>&nbsp; 作者: &nbsp; &nbsp; Levon819@msn.com<br>&nbsp; 日期: &nbsp; &nbsp; 2007-四月-11<br>&nbsp; 参数: &nbsp; &nbsp; ShutWinType:PShutType; PForce:Boolean<br>&nbsp; 结果: &nbsp; &nbsp; None<br>&nbsp; 功能: &nbsp; &nbsp; 关闭,重启,注销,休眠,待机系统等;<br>-----------------------------------------------------------------------------}<br><br>Procedure ShutDown(OperateMode: Integer; PForce: BOOLEAN = True);<br>Var<br>&nbsp; hToken, hProcess: thandle;<br>&nbsp; tp, prev_tp: TTokenPrivileges;<br>&nbsp; Len, Flags: DWORD;<br>&nbsp; CanShutdown: BOOLEAN;<br>Begin<br>&nbsp; If Win32Platform = VER_PLATFORM_WIN32_NT Then<br>&nbsp; Begin<br>&nbsp; &nbsp; hProcess := OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessId);<br>&nbsp; &nbsp; Try<br>&nbsp; &nbsp; &nbsp; If Not OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; Finally<br>&nbsp; &nbsp; &nbsp; CloseHandle(hProcess);<br>&nbsp; &nbsp; End;<br>&nbsp; &nbsp; Try<br>&nbsp; &nbsp; &nbsp; If Not LookupPrivilegeValue('', 'SeShutdownPrivilege',<br>&nbsp; &nbsp; &nbsp; &nbsp; tp.Privileges[0].Luid) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; tp.PrivilegeCount := 1;<br>&nbsp; &nbsp; &nbsp; tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; &nbsp; &nbsp; If Not AdjustTokenPrivileges(hToken, false, tp, SizeOf(prev_tp),<br>&nbsp; &nbsp; &nbsp; &nbsp; prev_tp, Len) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; Finally<br>&nbsp; &nbsp; &nbsp; CloseHandle(hToken);<br>&nbsp; &nbsp; End;<br>&nbsp; End;<br>&nbsp; CanShutdown := True;<br>&nbsp; // &nbsp;DoQueryShutdown(CanShutdown);<br>&nbsp; If Not CanShutdown Then<br>&nbsp; &nbsp; Exit;<br>&nbsp; If PForce Then<br>&nbsp; &nbsp; Flags := EWX_FORCE<br>&nbsp; Else<br>&nbsp; &nbsp; Flags := 0;<br>&nbsp; Case OperateMode Of<br>&nbsp; &nbsp; 1: ExitWindowsEx(Flags Or EWX_POWEROFF, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //断电;<br>&nbsp; &nbsp; 2: ExitWindowsEx(Flags Or EWX_SHUTDOWN, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //关闭;<br>&nbsp; &nbsp; 3: ExitWindowsEx(Flags Or EWX_REBOOT, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重启;<br>&nbsp; &nbsp; 4: ExitWindowsEx(Flags Or EWX_LOGOFF, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //注销<br>&nbsp; &nbsp; 5: SetSystemPowerState(True, PForce); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //待机;<br>&nbsp; &nbsp; 6: SetSystemPowerState(false, PForce); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//休眠;<br>&nbsp; End;<br>End;<br><br><br>window会由一个倒计时确认时间,就算你不点击或确认,时间一到,也会自动shutdown的
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部