如何获得过程清单 [英] how to get process list
问题描述
嘿
如何获取已在@ pc中运行的进程的列表
例如>
listBox1应该在PC上充满正在运行的程序.
我真的不知道如何得到它,我尝试了5种方法,但是它不会来.只是一个空列表.
另外,当我从列表框1按下xxxx.exe时(当它开始工作后),当按下按钮时,该按钮将关闭我选择的进程
如果我没事
Hey
How to get a list for processes which already running @ the pc
For example>
listBox1 should be filled with the running programs at the pc.
Dont know how to get it really , I tried over 5 ways and it wont come. just an empty list.
Also , a button when I press on xxxx.exe from the listbox1 (after I get it working) , when I press the button , It closes the process I''ve selected
If im right
foreach (Process prc in Process.GetProcessesByName("process.listbox1"))
{
prc.Kill();
}
所以,请帮帮我,
啊,一张图片来说明我的确切需求
http://i.imgur.com/cdjsV.png [
So , please help me out,
Ah , an image to explain what I exact need
http://i.imgur.com/cdjsV.png[^]
推荐答案
[除了Marcus的正确答案克莱默:]
用进程名称列出进程不是可靠的事情.两个完全不相关的进程可能会意外地使用相同的名称.此外,对任何名称进行硬编码都意味着难以维护的代码.我不知道您的目的,但是我可以假设您正在杀死同一应用程序的所有进程.在这种情况下,可以通过比较Process.MainModule.FileName
:
的值来检查应用程序是否相同. http://msdn.microsoft.com/en-us/library/system.diagnostics. process.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.mainmodule.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.diagnostics. processmodule.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. diagnostics.processmodule.filename.aspx [ ^ ].
当然,在这种情况下,您将无法检测到以不同名称执行的同一应用程序的副本,或者仅位于不同目录中的应用程序的副本,但是在这种情况下,只能对图像文件进行按位比较,您可能不需要考虑这种情况.
-SA
[In addition to correct answer by Marcus Kramer:]
Listing processes by the process name is not a reliable thing. Two totally unrelated processes can accidentally have the same name. Besides, hard-coding any name means poorly maintainable code. I don''t know your purpose, but I can assume you are killing all the processes of the same application. In this case, you can check up if the application is the same by comparing the value ofProcess.MainModule.FileName
:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainmodule.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.filename.aspx[^].
Of course, in this case, you won''t be able to detect the copy of the same application executed under some different name or just located in different directory, but, in this case, only a bitwise comparison of image files can help, you probably won''t need to consider such cases.
—SA
^ ]
一个非常快速的谷歌搜索在不到15秒的时间内找到了这个链接.作为开发人员,您将学到的最有价值的资产是如何通过Google找到解决方案.干杯.
Get a list of running Processes in C#[^]
A really quick google search found me this link in under 15 seconds. The most valuable asset you''ll ever learn as a developer is how to find solutions via google. Cheers.
这篇关于如何获得过程清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!