Delphi编写后台监控软件,Delphi编写后台监控软件
【 tulaoshi.com - Delphi 】
一、把当前进程变为一个系统服务: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.
四、说明:
在后台监控软件中使用以上功能,可真正实现隐蔽运行,热键调出,便于管理员进行管理。程序在Win98,Delphi5.0中运行通过。
来源:http://www.tulaoshi.com/n/20160129/1493286.html
看过《Delphi编写后台监控软件》的人还看了以下文章 更多>>