来源:www.cncfan.com | 2006-3-11 | (有3617人读过)
后台监控软件,为了达到隐蔽监控的目的,应该满足正常运行时,不显示在任务栏上,在按Ctrl+Alt+Del出现的任务列表中也不显示,管理员可以通过热键调出隐藏的运行界面。要作到这些,必须把当前进程变为一个系统服务,并且定义全局热键。
一、把当前进程变为一个系统服务:
目的是在任务列表中把程序隐藏起来。调用API函数RegisterServiceProcess实现。
二、定义全局热键(本例中定义热键Ctrl+Del+R),步骤:
1、定义捕获Windows消息WM_HOTKEY的钩子函数,即:procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
2、向Windows加入一个全局原子 Myhotkey: GlobalAddAtom(’MyHotkey’), 并保留其句柄。
3、向Windows登记热键:调用API函数RegisterHotKey实现。
三、源程序:
unit Unit1; interface uses Windows, Messages, Forms, Dialogs, Classes, Controls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private {热键标识ID} id: Integer; procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; { Privat-Declarations} public { Public-Declarations} end; var Form1 : TForm1; implementation const RSP_SIMPLE_SERVICE=1; function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord; stdcall; external ’KERNEL32.DLL’; {$R *.DFM}
{捕获热键消息} procedure TForm1.WMHotKey (var Msg : TWMHotKey); begin if msg.HotKey = id then ShowMessage(’Ctrl+Alt+R键被按下!’); form1.Visible :=true; end;
procedure TForm1.FormCreate(Sender: TObject); Const {ALT、CTRL和R键的虚拟键值} MOD_ALT = 1; MOD_CONTROL = 2; VK_R = 82; begin {首先判断程序是否已经运行} if GlobalFindAtom(’MyHotkey’) = 0 then begin {注册全局热键Ctrl + Alt + R} id:=GlobalAddAtom(’MyHotkey’); RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R); end else halt; end;
{把当前进程变为一个系统服务,从而在任务列表中把程序隐藏起来}
procedure TForm1.Button1Click(Sender: TObject); begin RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE); form1.Hide; end;
procedure TForm1.Button2Click(Sender: TObject); begin close; end; {退出时释放全局热键} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin UnRegisterHotKey(handle,id); GlobalDeleteAtom(id); end; end.
|