Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Windows ADO.NET Forms , +
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 9:33am
Edited 29-Oct-12 9:57am
Sergey Alexandrovich Kryukov at 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 at 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 at 29-Oct-12 15:33pm
Simple and accurate. My 5.
Marcus Kramer at 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
0 Sergey Alexandrovich Kryukov 9,578
1 OriginalGriff 8,420
2 Peter Leow 4,874
3 Kornfeld Eliyahu Peter 3,240
4 Maciej Los 2,356

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 29 Oct 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