Click here to Skip to main content
Rate this: bad
good
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)
{
   open_procs.Kill();
}
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
v3
Comments
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.
--SA
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
good
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 )
   {
      proc.Kill();
   }
}
  Permalink  
v2
Comments
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 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Oct 2012
Copyright © CodeProject, 1999-2014
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