Click here to Skip to main content
13,550,829 members
Rate this:
Please Sign up or sign in to vote.
See more:

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"))

So , please help me out,

Ah , an image to explain what I exact need[^]
Posted 20-Nov-12 4:52am
EFNijboer 20-Nov-12 11:00am
Why not use sysinternals suite (like Process Explorer/Monitor)?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Phoenix-1337 20-Nov-12 11:20am
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!
algioethqnbalkerunb 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.
SAKryukov 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.
SAKryukov 20-Nov-12 15:06pm
Agree, a 5.
SAKryukov 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180515.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100