如何获取进程ID以及如何从所有进程中杀死该特定进程?
大家好,
我需要开发用于创建流程的应用程序并从整个流程中删除特定流程文件。 br $> b $ b
注:
1.我打开了一张excel表,
2.现在我创建了另一张excel表vb.net运行时以编程方式。
3.我想通过编程方式单独杀死第二个进程。
4.不要杀掉第一个进程
先谢谢。
Hi All,
I need to develop the application for creating process and kill that particular process file from the whole processes.
Note:
1. I opened one excel sheet,
2. Now I creating another excel sheet through vb.net runtime programatically.
3. I want to kill the second process alone through programatically.
4. Do not kill first process
Thanks in Advance.
在这里你去...
Here you go...
Dim p As Process
p = New Process()
p.StartInfo.FileName = "filename_with_complete_path.xls"
p.Start()
并关闭它
and to close it
p.Kill()
如果文件要在打开文件的其他函数中关闭,请在全局范围内声明过程变量
If the file is to be closed in some other function than the one in which it was opened, declare the process variable
'p'
根据您的要求在适当的范围内)
globally (or within proper scope as per your requirement)
如果您是通过代码创建/打开Excel文件,只需关闭该文件并处置您用于创建/打开Excel文件的对象。
如果您发布代码如何创建/打开文件,那么我可能会尝试给您一个特定的解决方案。
暂时假设你为excel应用程序创建了一个对象excl,为所需的工作表创建了另一个对象wrkSht。
然后只需使用
wrkSht.Save()
wrkSht.Dispose()
excl.Dispose ()
我不认为任何人会建议杀死excel进程,当有更多可管理的方法来做你想做的事情时:)
If you are creating/opening an excel file through code, just close that file and dispose the object that you used to create/open the excel file.
If you post the code how you are creating/opening the file, then I may try to give you a specific solution.
For the time being lets assume you have created an object "excl" for excel application and another object "wrkSht" for the required work sheet.
then just use
wrkSht.Save()
wrkSht.Dispose()
excl.Dispose()
I dont think that any one would advice killing the excel process, when there are more managed ways to do what you want :)
Hi Mohankumar,
1 /我们必须选择新推出的流程PID
Hi Mohankumar,
1/ we have to select the newely created process PID
Process myProc = Process.Start("process full path");
int processId = myProc.Id;
2 /根据其PID终止进程
2/ to kill the process based on its PID
//we use the PID to select and kill that specific process
Process processes = Process.GetProcessById(processId);
processes.Kill();
希望它有所帮助。
Hope it helps.