斑竹求救,过路朋友看看 ,阻止关机问题(200分)

  • 主题发起人 wxjh2001
  • 开始时间
W

wxjh2001

Unregistered / Unconfirmed
GUEST, unregistred user!
现在一个有一个机房管理系统,(我不知道他的源代码),当时间到时自动关机,操作系统为98,我写了一个小程序,阻止系统关机,如下:在自己的机子上试时,我的程序运行时无法可以阻止使用“开始“菜单里的关机命令,但是,我放到装有这个管理系统的机子上时,机子照关不误,不只是何原因;?请大家帮助;我的程序运行时释放在系统托盘中的。<br>我使用了如下的消息处理过程<br>...........<br>&nbsp; procedure closemsg(var msg:TMessage); message wm_queryendsession;<br>..........<br>&nbsp; procedure Tform1.closemms;<br>&nbsp; begin &nbsp;<br>&nbsp;msg.wparam:=0;<br>&nbsp;msg.lparam:=........//这里没问题,只是我没记住,是win32sdk中的<br>&nbsp;end;<br><br>
 
好象最简单的方法是在FormCloseQuery中令canclose:=false; <br>
 
看看下面截获Windows关机消息的代码:<br>unit TesteandoEsta;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, WinTypes, WinProcs, Menus;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>procedure TForm1.WMQueryEndSession (var Message: TMessage);<br>var<br>&nbsp; Handled : Boolean;<br>begin<br>&nbsp; { 接收到消息时的通知}<br>&nbsp; if messagedlg('shutdown?',mtconfirmation,mbyesnocancel,0)= mryes then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Handled:=true<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Handled:=false;<br>end;<br>end.
 
请参考0485214:<br>OopsWare (2001-7-3 11:52:00) &nbsp;<br>今天也碰到此问题了,后来发现不是你程序的错! <br><br>关键在于那个关闭计算机的程序中ExitWindowsEx()使用了EWX_FORCE 参数. <br>见Delphi帮助的ExitWindowsEx: <br>&nbsp; Forces processes to terminate. When this flag is set, &nbsp;<br>&nbsp; Windows does not send the messages WM_QUERYENDSESSION &nbsp;<br>&nbsp; and WM_ENDSESSION to the applications currently &nbsp;<br>&nbsp; running in the system. This can cause the applications <br>&nbsp; to lose data. Therefore, you should only use this flag &nbsp;<br>&nbsp; in an emergency. <br><br>大体意思是使用了EWX_FORCE参数后,系统将不再广播WM_QUERYENDSESSION消息! <br>解决的办法也有,就是写一个HOOK的DLL,HOOK到ExitWindows和ExitWindowsEx <br>函数,屏蔽掉EWX_FORCE参数!似乎这样做有些累,但绝对有效,我是没时间 <br>做了,如果哪位做好了,别忘了通知我! <br><br>&nbsp;<br>
 
hook可以检测消息,没听说检测到函数,挂一个getmessage类型的hook,检测EWX_FORCE<br>消息可能行
 
关机的对话框都可以替换掉.
 
好象没办法吧。
 

Similar threads

顶部