Delphi編寫後台監視軟體

來源:互聯網
上載者:User

  後台監視軟體,為了達到隱蔽監控的目的,應該滿足正常運行時,不顯示在工作列上,在按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.

  四、說明:

  在後台監視軟體中使用以上功能,可真正實現隱蔽運行,熱鍵調出,便於管理員進行管理。程式在Win98,Delphi5.0中運行通過。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.