★★★关于 ExitWindowEx 函数的2个小问题。(100分)

  • 主题发起人 主题发起人 Tempter
  • 开始时间 开始时间
T

Tempter

Unregistered / Unconfirmed
GUEST, unregistred user!
大伙都知道,点“开始”再点“关机”,就跳出了关机菜单,选择“重起动计算机”,然后在点“是”的同时按下键盘上的“Shift”键就可以实现【快速】重起动系统。<br><br>小弟想知道的就是如何用ExitWindow或ExitWindowEx来实现上诉功能。<br><br>另外,小弟还想问一下如何用ExitWindow或ExitWindowEx来实现<br>“重起动计算机器并切换到MS-DOS状态”。<br><br>请各位大侠指教~ 感激不尽~ 
 
function GetWinVersion: String;<br>&nbsp;var<br>&nbsp; &nbsp; VersionInfo : TOSVersionInfo;<br>&nbsp; &nbsp; OSName &nbsp; &nbsp; &nbsp;: String;<br>&nbsp;begin<br>&nbsp; &nbsp; // set the size of the record<br>&nbsp; &nbsp; VersionInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );<br>&nbsp;<br>&nbsp; &nbsp; if Windows.GetVersionEx( VersionInfo ) then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with VersionInfo do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case dwPlatformId of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32s &nbsp; : OSName := 'Win32s';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows 95';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_NT &nbsp; &nbsp; &nbsp;: OSName := 'Windows NT';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; // case dwPlatformId<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := OSName + ' Version ' + IntToStr( dwMajorVersion ) + '.' + IntToStr( dwMinorVersion ) +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#13#10' (Build ' + IntToStr( dwBuildNumber ) + ': ' + szCSDVersion + ')';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // with VersionInfo<br>&nbsp; &nbsp; &nbsp; &nbsp;end // if GetVersionEx<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;Result := '';<br>&nbsp;end;<br>&nbsp;<br>&nbsp;procedure ShutDown;<br>&nbsp;const<br>&nbsp; &nbsp;SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; &nbsp; // Borland forgot this declaration<br>&nbsp;var<br>&nbsp; &nbsp;hToken &nbsp; &nbsp; &nbsp; : THandle;<br>&nbsp; &nbsp;tkp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TTokenPrivileges;<br>&nbsp; &nbsp;tkpo &nbsp; &nbsp; &nbsp; &nbsp; : TTokenPrivileges;<br>&nbsp; &nbsp;zero &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp;begin<br>&nbsp; &nbsp;if Pos( 'Windows NT', GetWinVersion) = 1 &nbsp;then // we've got to do a whole buch of things<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;zero := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br>&nbsp;<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SE_SHUTDOWN_NAME<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tkp.PrivilegeCount := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Boolean( GetLastError() ) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end // if Boolean( GetLastError() )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br>&nbsp; &nbsp; &nbsp; &nbsp;end // if OSVersion = 'Windows NT'<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;begin // just shut the machine down<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br>&nbsp; &nbsp; &nbsp; &nbsp;end; // else<br>&nbsp;end
 
ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 )好象是强制关闭所有进程然后关闭电源吧!<br><br>这个不是我想要的,请看清楚问题啊!
 
这样呢??<br>use &nbsp;ShlObj;<br>procedure ShutDown(Send: integer);<br>&nbsp; procedure AdjustToken(); //获取关机控制权<br>&nbsp; var<br>&nbsp; &nbsp; hdlProcessHandle, hdlTokenHandle, lBufferNeeded: Cardinal;<br>&nbsp; &nbsp; tmpLuid: Int64;<br>&nbsp; //tkpPrivilegeCount: Int64;<br>&nbsp; &nbsp; tkp, tkpNewButIgnored: TOKEN_PRIVILEGES;<br>&nbsp; &nbsp; Privilege: array[0..0] of _LUID_AND_ATTRIBUTES;<br>&nbsp; begin<br>&nbsp; &nbsp; hdlProcessHandle := GetCurrentProcess;<br>&nbsp; &nbsp; OpenProcessToken(hdlProcessHandle,<br>&nbsp; &nbsp; &nbsp; (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),<br>&nbsp; &nbsp; &nbsp; hdlTokenHandle);<br>&nbsp; // Get the LUID for shutdown privilege.<br>&nbsp; &nbsp; LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);<br>&nbsp; &nbsp; Privilege[0].Luid := tmpLuid;<br>&nbsp; &nbsp; Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; &nbsp; tkp.PrivilegeCount := 1; // One privilege to set<br>&nbsp; &nbsp; tkp.Privileges[0] := Privilege[0];<br>&nbsp; // Enable the shutdown privilege in the access token of this process.<br>&nbsp; &nbsp; AdjustTokenPrivileges(hdlTokenHandle,<br>&nbsp; &nbsp; &nbsp; False,<br>&nbsp; &nbsp; &nbsp; tkp,<br>&nbsp; &nbsp; &nbsp; Sizeof(tkpNewButIgnored),<br>&nbsp; &nbsp; &nbsp; tkpNewButIgnored,<br>&nbsp; &nbsp; &nbsp; lBufferNeeded);<br>&nbsp; end;<br>begin<br>&nbsp; AdjustToken;<br>&nbsp; case send of<br>&nbsp; &nbsp; 1: ExitWindowsEx(EWX_FORCE, 0); //在紧急情况下强制关机。 ;<br>&nbsp; &nbsp; 2: ExitWindowsEx(EWX_LOGOFF, 0); //以其他用户身份登录。 ;<br>&nbsp; &nbsp; 3: ExitWindowsEx(EWX_POWEROFF, 0); //关闭系统并关闭电源。<br>&nbsp; &nbsp; 4: ExitWindowsEx(EWX_REBOOT, 0); //重启操作系统<br>&nbsp; &nbsp; 5: ExitWindowsEx(EWX_SHUTDOWN, 0); //关机;<br>&nbsp; else<br>&nbsp; &nbsp; EXIT;<br>&nbsp; end;<br>end;
 
正在研究中...
 
小弟要实现的其实就是 不断电重启动 .<br>不过 用 exitwindow 和 exitwindowex都无法实现啊?
 
怎么个无法实现法?用了后有什么现象发生,讲清楚才行呀,老弟?
 

Similar threads

回复
0
查看
999
不得闲
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
922
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部