杀死一个进程列表中的进程后,怎样等待其运行结束并将占用资源全部释放干净?并能成果删除这个进程文件??(200分)

  • 主题发起人 主题发起人 minstrel
  • 开始时间 开始时间
M

minstrel

Unregistered / Unconfirmed
GUEST, unregistred user!
请给出详细代码!
 
没有人知道嘛????????
 
有意思的问题……:)
 
to duducat<br>高手会嘛?请指点一二
 
真不好意思,我现在在网吧!以后可能也不能上网了,如果你的<br>问题明年还没有人帮你解决的话,我可以帮助你……
 
啊…………不会让我等那么久吧!!!!!!!!!!!!!!!!难道这里就<br>没有其他高手了嘛???拜托各位了
 
if WaitForSingleObject(handle,INFINITE)=WAIT_OBJECT_0 then<br>&nbsp; deleteFile(processFileName)
 
to 车金明<br>&nbsp;WaitForSingleObject(handle,INFINITE)=WAIT_OBJECT_0 这一步老鼠错的,<br>该怎么办??<br>我的代码是这样的,可是不能删除文件<br>var<br>&nbsp; h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : THandle;<br>&nbsp; ExitCode &nbsp; &nbsp;: DWORD;<br>&nbsp; ProcessFile : string;<br>begin<br>&nbsp; ProcessFile:=ProcessLists.Selected.Caption;<br>h:=Openprocess(PROCESS_TERMINATE,False,DWORD(ProcessLists.Selected.Data));<br>&nbsp; &nbsp; &nbsp; &nbsp;if TerminateProcess(h,0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WaitforSingleObject(h,INFINITE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetExitCodeProcess(h,ExitCode);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;until ExitCode&lt;&gt;STILL_ACTIVE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(h);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Deletefile(ProcessFile);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;
 
为什么以上代码不能删除文件????????????真是怪!!!!!!!!!!!<br>SetFileAttributes(PChar(ProcessFile),FILE_ATTRIBUTE_NORMAL);<br>加了以上代码也没有用哟!!!!!!!<br>为什么???????????????????<br>谁能告诉我!!!!
 
&nbsp;我试了一下,XP里好像返回的szExeFile,没有包含路径,你说怎么可能删掉。<br>&nbsp; 比如我运行的是c:/windows/system32/cmd.exe,但它只返回一个cmd.exe,而你<br>用DeleteFile('cmd.exe');怎么可能成功嘛!<br>&nbsp; 我还没有想到好的办法哦!想到了再告诉你哦。好像XP里不用ToolHelp,用什么来<br>着,我忘咯!:
 
电脑爱好者杂志出版的《编程黑马真言》中有详细说明
 
to BeginDelphi 找到路径没有用的,不信你在98下面试试 关键不在这里<br>to UnderAttack难道真的要买这本书嘛?
 
进程管理函数<br>var<br>ProcessListHandle: THandle;<br>ProcessStruct &nbsp; &nbsp;: TProcessEntry32; <br>begin<br>ProcessLists.Items.Clear;<br>ProcessListHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPProcess,0);<br>ProcessStruct.dwSize:=Sizeof(ProcessStruct);<br>ok:=Process32First(ProcessListHandle,ProcessStruct);<br>while ok do<br>begin<br>with ProcessLists.Items.Add do<br>begin<br>Caption:=ProcessStruct.szExeFile;<br>……<br>end;<br>&nbsp;ok:=Process32Next(ProcessListHandle,ProcessStruct);<br>end;<br>end;
 
to minstrel 可以作如下修改试试!!<br>var<br>&nbsp; h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : THandle;<br>&nbsp; ExitCode &nbsp; &nbsp;: DWORD;<br>&nbsp; ProcessFile : string;<br>begin<br>&nbsp; ProcessFile:=ProcessLists.Selected.Caption;<br>h:=Openprocess(PROCESS_TERMINATE,False,DWORD(ProcessLists.Selected.Data));<br>&nbsp; &nbsp; &nbsp; &nbsp;if TerminateProcess(h,0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(h);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if &nbsp;FileExists(ProcessFile) and (MessageBox(0,PChar('要粉碎进程文件【'+ProcessFile+'】吗?'),'删除确认',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MB_Ok+MB_OKCANCEL+MB_ICONSTOP)=ID_OK) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Deletefile(ProcessFile);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>作了以上修改!经我调试可以删除文件了!!!!<br>如果还不删除的话,说明你显示进程信息的时候可能用到了之类的语句<br>CreateFile(PChar(FileName),GENERIC_READ, 1 ,@Security,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);<br>……以上语句会发生文件共享冲突!!!!不能进行任何操作!<br>
 
衷心感谢duducat最后作出了圆满的解答。问题已经解决了!!
 
后退
顶部