Click here to Skip to main content
11,641,087 members (63,996 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# C#4.0
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();
            }

So , please help me out,

Ah , an image to explain what I exact need
http://i.imgur.com/cdjsV.png[^]
Posted 20-Nov-12 4:52am
Comments
E.F. Nijboer at 20-Nov-12 11:00am
   
Why not use sysinternals suite (like Process Explorer/Monitor)?
http://technet.microsoft.com/en-us/sysinternals/bb842062
Rate this: bad
good
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:
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
  Permalink  
v2
Rate this: bad
good
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.
  Permalink  
v2
Comments
Phoenix 1337 at 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!
Marcus Kramer at 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 at 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 at 20-Nov-12 15:06pm
   
Agree, a 5.
--SA
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 Mika Wendelius 400
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 145
4 Afzaal Ahmad Zeeshan 129
0 Mika Wendelius 380
1 OriginalGriff 205
2 DamithSL 203
3 CPallini 125
4 Afzaal Ahmad Zeeshan 89


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2015
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