如何知道正在运行的所有exe文件的路径(100分)

  • 主题发起人 主题发起人 圣哥
  • 开始时间 开始时间

圣哥

Unregistered / Unconfirmed
GUEST, unregistred user!
用过一些函数,但是只能得到当前一个文件的路径,其他的路径我怎么得到?谢了!!!!
 
转贴一个, 参考一下吧<br><br>unit Find_Unit;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, TLHelp32, ComCtrls;<br><br>type<br>&nbsp; TProcessInfo=Record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExeFileName:String;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProcessID:DWord;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>type<br>&nbsp; TFindForm = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; SB: TStatusBar;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; function findthread(threadname:string):boolean;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; FindForm: TFindForm;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TFindForm.Button1Click(Sender: TObject);<br>var hfile:thandle; r:boolean; &nbsp;tf:string;<br>begin<br>&nbsp; r:=false; //查找空间变量是否存在 eg: in win2000 "cdrom0" is a space value<br>&nbsp; hfile:=createfile(pchar(edit1.Text),Generic_Read or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Generic_Write,File_Share_Read or File_Share_Write,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,Open_Existing,File_Attribute_Normal,0);<br>&nbsp; if hfile&lt;&gt;Invalid_Handle_Value then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(hfile);<br>&nbsp; &nbsp; &nbsp; &nbsp;r:=true;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; if r then sb.Panels[0].Text:='Space Find!' else sb.Panels[0].Text:='Space Not Found!';<br>&nbsp; tf:=edit2.text;<br>&nbsp; if pos('.',tf)=0 then tf:=tf+'.exe';<br>&nbsp; if findthread(tf) then sb.Panels[1].Text:='Thread Find!' else sb.Panels[1].Text:='Thread Not Found!';<br>end;<br><br>function TFindForm.findthread(threadname: string): boolean;<br>var &nbsp;//关键的过程<br>&nbsp; p:TProcessInfo;<br>&nbsp; OK:Bool;<br>&nbsp; ProcessListHandle:THandle;<br>&nbsp; ProcessStruct:TProcessEntry32;<br>begin<br>&nbsp; result:=false;<br>&nbsp; ProcessListHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);<br>&nbsp; ProcessStruct.dwSize:=SizeOf(ProcessStruct);<br>&nbsp; OK:=Process32First(ProcessListHandle,ProcessStruct);<br>&nbsp; while Integer(OK)&lt;&gt;0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; p.ExeFileName:=ProcessStruct.szExeFile;<br>// &nbsp; &nbsp; &nbsp;p.ProcessID:=ProcessStruct.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; OK:=Process32Next(ProcessListHandle,ProcessStruct);<br>&nbsp; &nbsp; &nbsp; if uppercase(p.ExeFileName)=uppercase(threadname) then begin result:=true; exit; end;<br>&nbsp; &nbsp; end;<br>&nbsp; closehandle(ProcessListHandle); &nbsp;<br>end;<br><br>end.<br><br><br><br>
 
我来贴一个——<br>_____________________________________________________________________________<br>由窗口句柄获得对应可执行文件名 &nbsp;<br>John Mollll<br><br><br>摘 要:由窗口句柄获得对应可执行文件名<br>关键字:句柄<br>类 别:系统控制<br>&nbsp;<br>&nbsp;<br>下面这个函数将根据窗口句柄参数返回相应程序的可执行文件名和路径。<br><br>function GetAppName(hwindow: HWND): string; <br>var <br>&nbsp; h : HMODULE; <br>begin <br>&nbsp; SetLength(Result, 100); <br>&nbsp; h:=GetClassLong(hwindow, GCL_HMODULE); <br>&nbsp; GetModuleFileName(h, PChar(Result), 100); <br>end; <br><br><br>用法: ShowMessage(GetAppName(FindWindow('notepad.exe', nil)));<br><br>投稿人:hubdog 投稿日期:2001-7-10 12:49:00 <br>&nbsp;<br>&nbsp;<br><br><br><br>本文共有评论3篇︱已被阅读过385次︱查看评论<br>_____________________________________________________________________________<br>
 
Process32First<br>Process32Next
 
uses TLHelp32;<br><br>type<br>&nbsp; &nbsp; TProcessInfo=Record<br>&nbsp; &nbsp; ExeFile:String;<br>&nbsp; &nbsp; ProcessID:Dword;<br>end;<br>&nbsp;pProcessInfo=^TProcessInfo;<br><br>function killexe(winpath:string):boolean;<br>var<br>p:pProcessInfo;<br>ContinueLoop:Bool;<br>FSnapshotHandle,hProcess:THandle;<br>FProcessEntry32:TProcessEntry32;<br>n:integer;<br>&nbsp;begin<br>&nbsp; &nbsp; &nbsp; New(p);<br>&nbsp; &nbsp; &nbsp; FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; &nbsp; &nbsp; FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br>&nbsp; &nbsp; &nbsp; ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);<br>&nbsp; &nbsp; &nbsp; while integer(ContinueLoop)&lt;&gt;0 do<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; p.ProcessID := FProcessEntry32.th32ProcessID;//获得进程ID<br>&nbsp; &nbsp; &nbsp; &nbsp; p.ExeFile:=FProcessEntry32.sZExeFile;//获得进程程序名<br>&nbsp; &nbsp; &nbsp; &nbsp; if SameText(p.ExeFile,winpath) then TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),p.ProcessID),0);//一但相等就KILL掉<br>&nbsp; &nbsp; &nbsp; &nbsp;Continueloop:=process32next(fsnapshothandle,fprocessentry32);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end;
 
后退
顶部