查询进程求助(50分)

  • 主题发起人 主题发起人 VaStars
  • 开始时间 开始时间
V

VaStars

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]<br>这是个查询运行中进行的函数,在98、2000下运行正常,但在NT4下就不行了。从跟踪的结果看,好像无法获得进程的信息,求助各位大虾了。<br>FileName是指在内存中查询同FileName的系统进程。<br>Function TFrm_Main.LookForProcess(var FileName:String;p:ProcessInfo):Integer;<br>var<br>&nbsp; ok &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Bool;<br>&nbsp; ProcessListHandle :Thandle; &nbsp; //进程的列表句柄<br>&nbsp; ProcessStruct &nbsp; &nbsp; :TProcessEntry32; &nbsp;//进程的结构,进程的信息<br>&nbsp; Flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:Integer;<br>begin<br>&nbsp; //利用CreateToolhelp32Snapshot 函数得到进程列表的句柄<br>&nbsp; ProcessListHandle &nbsp; &nbsp;:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; ProcessStruct.dwSize := Sizeof(ProcessStruct);<br>&nbsp; ok :=Process32First(ProcessListHandle,ProcessStruct); &nbsp; //得到第一个进程<br>&nbsp; Flag := 0;<br>&nbsp; while integer(ok) &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; If Trim(ProcessStruct.szExeFile) = Trim(FileName) then &nbsp; //发现进程<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.ProcessID:=ProcessStruct.th32ProcessId;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Flag &nbsp; :=1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; Else ok &nbsp;:=Process32Next(ProcessListHandle,ProcessStruct); //寻找下一个进程<br>&nbsp; &nbsp; end;<br>&nbsp; LookForProcess := Flag;<br>end;
 
我刚做一个,帖给你:<br>var<br>&nbsp; lppe: TProcessEntry32;<br>&nbsp; found : boolean;<br>&nbsp; Hand : THandle;<br>begin<br>&nbsp; &nbsp; System.Items.Clear;<br>&nbsp; &nbsp; SystemRunIDList.Items.Clear;<br>&nbsp; &nbsp; Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br>&nbsp; &nbsp; found := Process32First(Hand,lppe);<br>&nbsp; &nbsp; TempI:=0;<br>&nbsp; &nbsp; while found do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; system.Items.Add(StrPas(lppe.szExeFile));<br>&nbsp; &nbsp; &nbsp; SystemRunIDList.Items.Add(IntToStr(lppe.th32ProcessID));<br>&nbsp; &nbsp; &nbsp; found := Process32Next(Hand,lppe);<br>&nbsp; &nbsp; &nbsp; TempI:=TempI+1;<br>&nbsp; &nbsp; end;<br>end;<br>
 
1楼的代码和我的没有区别呀,在NT4下也不行的……
 
哪位富哥富姐的帮忙看看呀,小弟在线上等着呢。
 
TO VaStars<br>我这个代码在2000个调试通过的。
 
我的开发环境也是2K的,没有问题,98下也使用通过。但NT 4下无法查找进程。<br>kenbe兄可以看一下,其实我们的主功能代码是一样的。
 
后退
顶部