如何将已运行的程序陈列出来(30分)

  • 主题发起人 主题发起人 tangyi_001
  • 开始时间 开始时间
T

tangyi_001

Unregistered / Unconfirmed
GUEST, unregistred user!
如果将已运行的程序陈列出来,那么就可以对其中一个定时关闭。
 
FindWindow来进行枚举。<br>http://www.csdn.net/Delphi/index.htm有例子。
 
findwindow好象是找某一窗体的吧。*.exe;*.com就不知行不行<br>(如何判断是不是*.exe;*.com)
 
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=161134
 
显示所有运行的程序<br>var<br>&nbsp; &nbsp; pTask : pTaskEntry;<br>&nbsp; &nbsp; Task &nbsp;: bool;<br>&nbsp; &nbsp; Pstr &nbsp;: array [0..79] of Char;<br>&nbsp; &nbsp; Str &nbsp; : string[80];<br>&nbsp; &nbsp; byt_j : byte;<br>begin<br>&nbsp; ListBox1.Clear;<br>&nbsp; GetMem(pTask, SizeOf(TTaskEntry));<br>&nbsp; pTask^.dwSize:=SizeOf(TTaskEntry);<br>&nbsp; byt_j:=0;<br>&nbsp; Task:=TaskFirst(pTask);<br>&nbsp; While Task do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; inc(byt_j);<br>&nbsp; &nbsp; &nbsp; Str:=StrPas(pTask^.szModule);<br>&nbsp; &nbsp; &nbsp; Listbox1.Items.Add(Str);<br>&nbsp; &nbsp; &nbsp; Task:=TaskNext(pTask);<br>&nbsp; &nbsp; end;<br>&nbsp; Label1.Caption:=IntToStr(byt_j)+ ' tasks found';<br>end;
 
浪刀:你好!<br>&nbsp; &nbsp; 你提供的程序编译出错,如下:<br>&nbsp; &nbsp; ptaskentry未定义.<br>&nbsp; &nbsp; 请问ptaskentry怎样声明
 
去"计算机世界"网站里的delphi技巧专栏,里面有我发表的一篇文章叫"如何访问<br>进程的内存空间"里面用到了几个函数列出所有的进程,有源码.
 
用api函数getwindow(也可用enumwindows)能得到当前所有运行的窗口的句柄,<br>然后用getwindowtext得到该窗口标题,与要关闭的程序窗口标题比较。<br>
 
to 浪刀:<br>&nbsp; &nbsp; 你的程序编译有错,ptaskentry未定义.<br>&nbsp; &nbsp;
 
//列出当前的进程中的文件路径<br>1.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>2.ProcessFirst<br>3.ProcessNext;<br>试一下吧,我前几天刚刚搞定,派上用途了。<br><br>(* &nbsp;Windows NT: Requires version 5.0 or later.<br>&nbsp; Windows: Requires Windows 95 or later.<br>&nbsp; Windows CE: Unsupported.<br>&nbsp; Header: Declared in tlhelp32.h.<br>&nbsp; Import Library: Use kernel32.lib.*)<br><br>uses tlhelp32;<br>Function ListRuningExeName(ExeName:TStrings):Integer;<br>Var<br>&nbsp; &nbsp; iHandle:LongInt;<br>&nbsp; &nbsp; lppe:tagProcessentry32;<br>&nbsp; &nbsp; i:integer;<br>begin<br>&nbsp; &nbsp; i:=0;<br>&nbsp; &nbsp; iHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; if iHandle=-1 then &nbsp; &nbsp;Raise Exception.Create('调用失败!');<br>&nbsp; &nbsp; &nbsp; &nbsp; Process32First(iHandle,lppe);<br>&nbsp; &nbsp; &nbsp; &nbsp; While GetLastError&lt;&gt;ERROR_NO_MORE_FILES do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExeName.Add(lppe.szExeFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process32Next(iHandle,lppe);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp;On E:Exception do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Application.HandleException(E);<br>&nbsp; &nbsp; &nbsp; &nbsp; i:=-1;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(iHandle);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:=i;<br>&nbsp; &nbsp; end;<br>end;<br>
 
接受答案了.
 
后退
顶部