一个常见于网上的在任务栏和任务列表中隐藏程序的源代码的问题(100分)

  • 主题发起人 主题发起人 icanfly
  • 开始时间 开始时间
I

icanfly

Unregistered / Unconfirmed
GUEST, unregistred user!
后台监控软件,为了达到隐蔽监控的目的,应该满足正常运行时,不显示在任务栏上,在按Ctrl+Alt+Del出现的任务列表中也不显示,管理员可以通过热键调出隐藏的运行界面。要作到这些,必须把当前进程变为一个系统服务,并且定义全局热键。<br><br>  一、把当前进程变为一个系统服务: <br><br>  目的是在任务列表中把程序隐藏起来。调用API函数RegisterServiceProcess实现。 <br><br>  二、定义全局热键(本例中定义热键Ctrl+Del+R),步骤: <br><br>  1、定义捕获Windows消息WM_HOTKEY的钩子函数,即:procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br><br>  2、向Windows加入一个全局原子 Myhotkey: GlobalAddAtom(’MyHotkey’), 并保留其句柄。 <br><br>  3、向Windows登记热键:调用API函数RegisterHotKey实现。 <br><br>  三、源程序: <br><br>unit Unit1; <br>interface <br>uses <br>Windows, Messages, Forms, Dialogs, Classes, Controls, StdCtrls; <br>type <br>TForm1 = class(TForm) <br>Button1: TButton; <br>Button2: TButton; <br>procedure FormCreate(Sender: TObject); <br>procedure Button1Click(Sender: TObject); <br>procedure Button2Click(Sender: TObject); <br>procedure FormClose(Sender: TObject; var Action: TCloseAction); <br>private <br>{热键标识ID} <br>id: Integer; <br>procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br>{ Privat-Declarations} <br>public <br>{ Public-Declarations} <br>end; <br>var <br>Form1 : TForm1; <br>implementation <br>const RSP_SIMPLE_SERVICE=1; <br>function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord; stdcall; external ’KERNEL32.DLL’; <br>{$R *.DFM} <br><br>{捕获热键消息} <br>procedure TForm1.WMHotKey (var Msg : TWMHotKey); <br>begin <br>if msg.HotKey = id then <br>ShowMessage(’Ctrl+Alt+R键被按下!’); <br>form1.Visible :=true; <br>end; <br><br>procedure TForm1.FormCreate(Sender: TObject); <br>Const <br>{ALT、CTRL和R键的虚拟键值} <br>MOD_ALT = 1; <br>MOD_CONTROL = 2; <br>VK_R = 82; <br>begin <br>{首先判断程序是否已经运行} <br>if GlobalFindAtom(’MyHotkey’) = 0 then <br>begin <br>{注册全局热键Ctrl + Alt + R} <br>id:=GlobalAddAtom(’MyHotkey’); <br>RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R); <br>end <br>else <br>halt; <br>end; <br>&nbsp;<br><br>  {把当前进程变为一个系统服务,从而在任务列表中把程序隐藏起来} <br><br><br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE); <br>form1.Hide; <br>end; <br><br>procedure TForm1.Button2Click(Sender: TObject); <br>begin <br>close; <br>end; <br>{退出时释放全局热键} <br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); <br>begin <br>UnRegisterHotKey(handle,id); <br>GlobalDeleteAtom(id); <br>end; <br>end. <br>&nbsp;<br><br>  四、说明: <br><br>  在后台监控软件中使用以上功能,可真正实现隐蔽运行,热键调出,便于管理员进行管理。程序在Win98,Delphi5.0中运行通过。 <br>/////////////////////////////<br>我使用时发现的问题????请指教<br><br>问题:查API函数RegisterServiceProcess 帮助里没有这个函数。<br>&nbsp; &nbsp; &nbsp; 在win2000下编译通过但运行时报错:无法定位程序输入点RegisterServiceProcess于动态链接库KERNEL32.DLL上
 
我查到了:<br><br>The RegisterServiceProcess function registers or unregisters a service process. A service process continues to run after the user logs off. <br><br>DWORD RegisterServiceProcess(DWORD dwProcessId, <br>&nbsp; &nbsp; DWORD dwType);<br><br>Parameters<br><br>dwProcessId<br><br>Specifies the identifier of the process to register as a service process. Specifies NULL to register the current process. <br><br>dwType<br><br>Specifies whether the service is to be registered or unregistered. This parameter can be one of the following values. <br><br>Value Meaning<br>RSP_SIMPLE_SERVICE Registers the process as a service process.<br>RSP_UNREGISTER_SERVICE Unregisters the process as a service process.<br>&nbsp;<br><br>Return Value<br><br>The return value is 1 if successful or 0 if an error occurs.<br>
 
The following function is supported by the Windows 95 Service Control Manager. <br><br>RegisterServiceProcess<br>&nbsp;<br>
 
请问有没有2000下相应的函数实现相同的功能?谢谢!
 
在2000下不是API的问题,而是可以做成服务程序,但不能隐藏。<br>关于在2000下进程的隐藏,请查阅其它帖子:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1705090<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=985941<br>
 
接受答案了.
 
后退
顶部