Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
foreach (Process prc in Process.GetProcessesByName("process.listbox1"))
           {
               prc.Kill();
           }


So , please help me out,

Ah , an image to explain what I exact need
http://i.imgur.com/cdjsV.png[^]
Posted
Comments
E.F. Nijboer 20-Nov-12 11:00am    
Why not use sysinternals suite (like Process Explorer/Monitor)?
http://technet.microsoft.com/en-us/sysinternals/bb842062

[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 of 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[^].

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
 
Share this answer
 
v2
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.
 
Share this answer
 
v2
Comments
Phoenix 1337 20-Nov-12 11:20am    
Well
I have searched @google.
All codes arent work as well , some giving errors , some wont even work.
Thats why I asked here
and , sorry about that but . I didnt posted smth here to get this kind of reply.
I post for help!
fjdiewornncalwe 20-Nov-12 14:05pm    
Because you didn't show anything codewise that you have tried, the assumption will be made that you haven't tried any of the simple google search stuff. Unfortunately that is the habit of a large majority of people asking questions. If you have done that and not gotten results, it would be a good idea to mention that in your question so that you don't get a response like mine. Sorry if it was not appropriate to the situation.
If you post a snippet of what you've tried and exceptions and such you are getting then I'm certain I can help you along your way. Cheers.
Sergey Alexandrovich Kryukov 20-Nov-12 15:16pm    
The bad habit is trying to find out a code sample in all cases, instead of actually writing some code. It can lead to complete lack of programming capabilities...
In this case, looking at MSDN help page and writing code just "by definition" would be the simplest obvious thing.
--SA
Sergey Alexandrovich Kryukov 20-Nov-12 15:06pm    
Agree, a 5.
--SA
Sergey Alexandrovich Kryukov 20-Nov-12 15:14pm    
By the way, hard-coding the process name is bad in principle. I provided useful further advice, please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900