闲置状态一段时间后自动运行某个程序(50分)

  • 主题发起人 主题发起人 flash9
  • 开始时间 开始时间
F

flash9

Unregistered / Unconfirmed
GUEST, unregistred user!
我测试到下面的代码在WINXP下,一旦用Ctrl+Alt+Del之后,hook就失效了,不能检测到键<br>盘和鼠标的重新动作。请问是哪里出了问题呢? &nbsp;<br><br>unit hook;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hHook: integer;<br>&nbsp; Timesnum: integer;<br><br>implementation<br><br>{$R *.dfm}<br><br>const<br>&nbsp; &nbsp;Timescount = 10;<br><br>function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;<br>begin<br>&nbsp; &nbsp;Timesnum := 0;<br>&nbsp; &nbsp;Result := 0;<br>end;<br><br>function StartHook: Boolean;<br>begin<br>&nbsp; &nbsp;Result := False;<br>&nbsp; &nbsp;if hHook = 0 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;if hHook &gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := True;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure StopHook;<br>begin<br>&nbsp; &nbsp;if hHOok &gt; 0 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;UnHookWindowsHookEx(hHook);<br>&nbsp; &nbsp; &nbsp; &nbsp;hHook := 0;<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;hHook := 0;<br>&nbsp; &nbsp;StartHook();<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; stophook;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>&nbsp; &nbsp;inc(Timesnum);<br>&nbsp; &nbsp;label1.Caption := floattostr(Timesnum);<br>&nbsp; &nbsp;if Timesnum &gt;= Timescount then<br>&nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('ok');<br>end;<br><br>end.<br>
 
在98下注册成系统服务可以让CTRL+ALT+DEL 看不到,在XP下不能这样比较复杂。
 
写一个屏幕保护程序,功能是启动你的程序,呵呵。
 
我也发现这个问题,如果按键钩子不用dll,当按下Ctrl+Alt+Del之后,hook就失效了,<br>不能检测到键盘和鼠标的动作,不只xp,在我的机子上2000,98也是如此,<br>但改用dll,就没有这个问题了,不知道为什么?
 
NowCan的思路到是有趣,模拟成一个屏幕保护程序,然后自动将自己设为<br>当前屏保,再设置时间,之后监测就由系统来做了,呵呵!
 
刘:有没有写成DLL的具体例子?贴上来吧?我可是比较菜,不懂的喔!
 
方法A:监测Ctrl+Alt+Del,不让它运行。<br>方法B:做个时钟判断,定期把程序后台激活了再隐藏。<br>方法C:别利用屏幕保护。自己写一个类似的exe。
 
我有,到这里下载这个代码看看:http://www.efile.com.cn/?liumazi ,不知是否对您有帮助?<br>对了,下载:ajgz.rar
 

Similar threads

I
回复
0
查看
628
import
I
I
回复
0
查看
547
import
I
I
回复
0
查看
586
import
I
后退
顶部