如何实时检测win98系统中运行的应用程序(100分)

  • 主题发起人 主题发起人 drank
  • 开始时间 开始时间
D

drank

Unregistered / Unconfirmed
GUEST, unregistred user!
我想设定一个HOOK使其能实时检测在win98系统中运行的应用程序。<br>我试过setwindowshookex(wh_cbt,spy,hinstance,0) 和<br>setwindowshookex(wh_shell,spy,hinstance,0)但结果是,只要一挂起,则任何应用程序<br>都无法运行。<br>spy 的代码如下:<br>if code=HCBT_CREATEWND then<br>&nbsp; begin<br>&nbsp; &nbsp; messagebeep(mb_ok);<br>&nbsp; &nbsp; getwindowtext(wparam,@i,255);<br>&nbsp; &nbsp; form1.listbox1.Items.Add(strpas(@i));<br>&nbsp; &nbsp; result:=0;<br>&nbsp; end<br>else<br>&nbsp; result:=callnexthookex(hookhandle,code,wparam,lparam);<br>请问该如何解决??????? &nbsp;
 
有没有人可以回答我。
 
为什么只有人浏览,却没人过来帮帮我,嫌分太少,我可再加。。。。。拜托
 
用findwindow查找程序的window不行吗?
 
我需要实时监控,如果是隔几分钟找一次一会占用系统资源二无时效性
 
在Application.Onidle事件中用FindWindow来检查吧。
 
to 教父<br>&nbsp; &nbsp;我不认为这是一个好办法,这样会占用很多系统资源,而且这种方式是主动的搜索,而不是<br>被动的应答,我需要的是被动应答。<br>&nbsp; &nbsp;我试过使用shell hook,但是用getwindowtext检测不到98自己的应用程序的窗口名字,且<br>运行ie后会死机。不知有什么api函数可检测运行的应用程序的文件名,及有什么办法可避免ie<br>运行死机。
 
在Application.Onidle事件中写代码虽然CPU的占用率为100%,但实际上并不会对系统造成太大的<br>影响。
 
to 教父<br>&nbsp; &nbsp;不知有没有办法可帮我解决ie运行会死机的问题.
 
用Findwindows不会导致IE死机吧。<br>如果你非要用HOOK的方法的话我也没有试过,我再看看吧。
 
to教父<br>&nbsp; &nbsp; 今天我又试了试,死机没有了,不过一些系统的窗口如ie,我的电脑等,得不到窗口标题.<br>另外窗口标题是在不断变化的.最终我是要得到运行的应用程序的文件名,如iexplorer.exe,<br>notepad.exe.不知你有否办法.<br>
 
COPY一段内容给你,希望能对你有用。<br><br>Question<br><br>I am using FindWindow() to locate a window handle and I<br>am using PostMessage() to close the application.<br>The problem is that I can't seem to close Acrobat Reader<br>using FindWindow(nil, 'Acrobat Reader') and PostMessage()<br>whenever Acrobat Reader has a file opened.<br>Using winsight.exe, I noticed that Acrobat Reader changes<br>its classname and window title whenever a PDF file is<br>opened. How do I find Acrobat Reader's window handle and<br>send a message to close the application when the<br>classname and title change?<br>Answer<br><br>A:<br>You should use Getwindow() to cycle thru all the various windows and search<br>each one's <br>name for acrobat reader, although this sounds like a chore it's really not<br>too tough and happens instantaneously when you run the program.<br><br>Here's the code to do it :<br>(* Function to get the handle of Adobe Acrobat, could be applied to any<br>&nbsp;partial text window of a main program such as notepad, just change the<br>"Acrobat <br>Reader" to the appropriate thing you're looking for, it will return 0 if the<br>window<br>wasn't found will return the handle if it was found &nbsp; &nbsp; *)<br><br>Function GetAcrobatHwnd : word;<br><br>var<br>&nbsp; hwndx :word;<br>&nbsp; PString : Pchar;<br>&nbsp; txtlength : integer;<br>&nbsp; posit : byte;<br>begin{function}<br>&nbsp;hwndx := Getdesktopwindow;<br>&nbsp;GetWindow(hwndx,GW_CHild);<br>&nbsp;While not done do<br>&nbsp;begin<br>&nbsp;Txtlength := GetWindowText(hwndx,PString,255);<br>&nbsp;Posit := Pos("Acrobat Reader",Strpas(Pstring));<br>&nbsp; &nbsp; &nbsp; &nbsp; If Posit &gt; 0 then (* Acrobat was found, make the result the handle *)<br>&nbsp; &nbsp; &nbsp; &nbsp; begin {if} &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := hwndx;<br>&nbsp; &nbsp; &nbsp; &nbsp; done := true;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;{if}<br>&nbsp; if hwndx = Getwindow(hwndx,GW_Hwndlast) then (* Acrobat Isn't Running *)<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; done := true;<br>&nbsp; &nbsp; end;<br>hwndx := GetWindow(hwndx,GW_HWNDNEXT);<br>&nbsp;end;{while}<br><br>end;{function GetAcrobatHwnd}<br><br><br>
 
利用钩子程序吧,当程序打开时要触发窗口事件,当你发现了一个新的窗口句并时可以触发通知<br>这样不就可以了吗?
 
谢谢各位关心!!!!<br>我已成功的用shell hook捕捉了窗口的创建事件,但任然有些问题,现提出来与大家讨论:<br>&nbsp; &nbsp;在我使用了挂起hook之后,应用程序的创建事件我能捕捉,但,凡是在钩子挂起之后运行的<br>应用程序,无论什么类型,只要进行了minimize 操作,就会隐藏hide起来.且在taskbar上也<br>找不到.只有用alt+tab切换才会出现.........不知什么问题.我把原代码贴上,请大家帮忙<br>研究.<br><br>以下是测试程序的原代码<br>unit testmain;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls,tlhelp32, AppEvnts;<br><br>&nbsp;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; ApplicationEvents1: TApplicationEvents;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; &nbsp; &nbsp; var Handled: Boolean);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; <br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; mymsg:dword;<br><br><br><br><br><br>type<br>EDLLLoadError=class(exception);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>implementation <br>{$R *.DFM} &nbsp; <br>function createhook:bool; external 'mydll.dll' ;<br>function freehook:bool; external 'mydll.dll' ;<br><br>var hookhandle:hhook=0;<br>&nbsp; &nbsp; oldwinproc:pointer;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>close;<br>end;<br><br>function newproc(windowhandle:hwnd; themessage, paramw,paraml:longint):longint; stdcall;<br>var <br>&nbsp; &nbsp; pid:integer;<br>&nbsp; &nbsp; ps:tprocessentry32;<br>&nbsp; &nbsp; hp:thandle;<br>&nbsp; &nbsp; filename:string;<br>&nbsp; &nbsp; isend:bool;<br>begin<br>&nbsp; &nbsp; result:=0;<br>&nbsp;if themessage=mymsg then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; form1.listbox1.Items.Clear;<br>&nbsp; &nbsp; getwindowthreadprocessid(paramw,@pid);<br>&nbsp; &nbsp; hp:= createtoolhelp32snapshot(TH32CS_SNAPPROCESS,pid);<br>&nbsp; &nbsp; ps.dwsize:=sizeof(ps); &nbsp; &nbsp;<br>&nbsp; &nbsp; isend:=process32first(hp,ps);<br>&nbsp; &nbsp; while isend do <br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; filename:=ps.szExeFile; <br>&nbsp; &nbsp; &nbsp; form1.listbox1.Items.Add('w'+filename);<br>&nbsp; &nbsp; &nbsp; isend:=process32next(hp,ps);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; result:=0;<br>&nbsp; &nbsp;end<br>&nbsp;else<br>&nbsp; &nbsp;result:=callwindowproc(oldwinproc,form1.handle,themessage,paramw,paraml);<br>end;<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br><br>var lb:bool; &nbsp;<br>begin<br><br>&nbsp; mymsg:=registerwindowmessage('cbtcreatewndmessage');<br>&nbsp; oldwinproc:=pointer(setwindowlong(form1.handle,gwl_wndproc,longint(@newproc)));<br><br>lb:=createhook; &nbsp;<br>end;<br><br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var lb:bool;<br>begin<br>lb:=freehook;<br><br>end;<br><br>procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; var Handled: Boolean);<br>var <br>&nbsp; &nbsp; pid:integer;<br>&nbsp; &nbsp; ps:tprocessentry32;<br>&nbsp; &nbsp; hp:thandle;<br>&nbsp; &nbsp; filename:string;<br>&nbsp; &nbsp; isend:bool;<br>begin<br>&nbsp; if msg.message=mymsg then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; form1.listbox1.Items.Clear;<br>&nbsp; &nbsp; getwindowthreadprocessid(msg.wParam,@pid);<br>&nbsp; &nbsp; hp:= createtoolhelp32snapshot(TH32CS_SNAPPROCESS,pid);<br>&nbsp; &nbsp; ps.dwsize:=sizeof(ps); &nbsp; &nbsp;<br>&nbsp; &nbsp; isend:=process32first(hp,ps);<br>&nbsp; &nbsp; while isend do <br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; filename:=ps.szExeFile; <br>&nbsp; &nbsp; &nbsp; form1.listbox1.Items.Add('w'+filename);<br>&nbsp; &nbsp; &nbsp; isend:=process32next(hp,ps);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;showwindow(msg.wparam,SW_normal);<br><br>&nbsp; &nbsp;end;<br>&nbsp;<br><br>end;<br><br>end.<br><br><br>以下是dll中的原代码<br>unit cbt;<br><br>interface<br><br>uses<br>messages,windows;<br><br>function createhook:bool;stdcall;<br>function freehook:bool;stdcall;<br>function cbtcreatewndhook( &nbsp;int: integer; // hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WPARAM: longint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// depends on hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPARAM: longint // depends on hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;):longint &nbsp;stdcall;<br><br><br><br>&nbsp; &nbsp;<br>implementation<br><br>var hookhandle:hhook=0;<br><br>function cbtcreatewndhook( &nbsp;int: integer; // hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WPARAM: longint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// depends on hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPARAM: longint // depends on hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;):longint ; <br>begin<br>result:=0;<br>if int=Hshell_WINDOWCREATED &nbsp;then<br>&nbsp;begin<br>&nbsp; lparam:=getwindowlong(wparam,GWL_STYLE);<br>&nbsp; postmessage(HWND_BROADCAST,registerwindowmessage('cbtcreatewndmessage'),wparam,lparam);<br>&nbsp;end<br>else<br>&nbsp;result:= callnexthookex(hookhandle,int,wparam,lparam);<br>end;<br><br>function createhook:bool; <br>begin<br>hookhandle:=setwindowshookex(wh_shell,cbtcreatewndhook,hinstance,0);<br>result:=hookhandle&lt;&gt;0;<br>end;<br><br>function freehook:bool;<br>begin<br>result:=unhookwindowshookex(hookhandle);<br>end;<br><br>end.<br><br>以下是dll接口程序的代码<br>library mydll;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; windows,<br>&nbsp; messages,<br>&nbsp; cbt in 'cbt.pas';<br><br>const<br>&nbsp; cbtgothandle=wm_user+101;<br><br>{$R *.RES}<br>exports<br>&nbsp;createhook,freehook,cbtcreatewndhook;<br><br>begin<br><br>end.
 
copy to see!<br>waiting……
 
网上没有人可帮我吗?
 
這樣搞掂!<br>unit exelook;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; procedure Button1Click(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><br>implementation<br><br>uses TLHelp32;<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>VAR<br>&nbsp; &nbsp;LPPE: TPROCESSENTRY32;<br>&nbsp; &nbsp;FOUND: BOOLEAN;<br>&nbsp; &nbsp;HAND:THANDLE;<br>begin<br>&nbsp; &nbsp;Hand:= CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; &nbsp;found:= Process32First(Hand,lppe);<br>&nbsp; &nbsp;while found do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;listBox1.items.add(strPas(lppe.szExefile));<br>&nbsp; &nbsp; &nbsp;found:= Process32Next(hand,lppe);<br>&nbsp; &nbsp;end;<br>end;<br><br>end.
 
to:jellyman <br>&nbsp; &nbsp;十分感谢,不过你所讲的内容对我早已不是问题,请帮我解决挂起hook后其他应用程序的<br>运行异常问题。见我最后一次提问。<br>to:gcq<br>&nbsp; &nbsp;研究的结果如何<br><br><br>to: everyone<br>&nbsp; &nbsp;各位,这是一个十分有趣的问题,肯定你没有碰倒过。搞定他有大奖。问题请见我最进<br>一次在本页上贴的帖子。
 
不明白,干吗一定要用HOOK呢?用JELLYMAN的方法,绝对可以列出系统所有正在运行的程<br>序,包括了像BO、冰河之类的木马程序。如果说要如果系统一有程序运行或退出就自动更<br>新程序列表,那就做个定时刷新啊,虽说没HOOK实时,但在WIN2000中的那个任务管理器<br>也不是HOOK这种实时更新的。且,用HOOK来实时更新,有必要吗?我真的不明白<br>
 
各位高手:<br>我不想这样快就放弃这一课题,所以请正面回答我提出的问题。<br>我需要做到的效果是实时的检测应用程序的开启和关闭。拜托!!!!!
 
后退
顶部