Click here to Skip to main content
13,005,991 members (109,477 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone,

I'm trying to add this functionality of checking for open processes and killing it if that is the case. This is what I have so far:
Process[] open_procs = Process.GetProcessesByName("PicoScope.exe");
if (open_procs.Length > 0)

It's not finding the Kill command within the open_procs available commands. Can someone shed some light as to how I can proceed with this?
Posted 29-Oct-12 8:33am
Updated 29-Oct-12 8:57am
Sergey Alexandrovich Kryukov 29-Oct-12 15:42pm
It's pretty much apparent that you are doing something dirty instead of regular development. No matter how good are the techniques you would use and how good advice you have, you won't get an acceptable resolution of the problem, because your goal is already wrong. This is because you are not addressing to root of the problem at all. And you did not explain your ultimate goal, so you cannot hope for success in this way.
joshrduncan2012 29-Oct-12 15:46pm
How can you assume something like that? My intent is that if that the 3rd party process that this program opens is already open, then to kill that process first before launching the new 3rd party process. We don't want to have more than 1 instantiation of the same 3rd party process open at the same time. My program is supposed to add a new menu option to the menu of the 3rd party program. This has nothing to do with anything dirty. What goal are you referring to that you say is "wrong"? I'm not sure I understand that.

1 solution

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

Solution 1

You are trying to kill the array of processes, rather than the individual processes themselves.
You need to loop through them like this.
Process[] open_procs = Process.GetProcessesByName("PicoScope.exe");
if( open_procs.Length > 0 )
   foreach( var proc in open_procs )
RaisKazi 29-Oct-12 15:33pm
Simple and accurate. My 5.
Marcus Kramer 29-Oct-12 16:10pm
Thanks, Rais.

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 | Mobile
Web02 | 2.8.170628.1 | Last Updated 29 Oct 2012
Copyright © CodeProject, 1999-2017
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