Jump to content

Kill process not working

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
I'm new to C# but I tried to write an application to terminate a process.

try
            {
                Process[] processes = Process.GetProcessesByName(processName);
                Console.Write("Got processes\n");
                foreach (Process process in processes)
                {
                    process.Kill();
                    Console.Write(processName + "TERMINATED!\n" + "+n");
                }
            }
            catch(InvalidOperationException)
            {
                Console.Write("ERROR CODE 12: Invalid Operation");
            }

I put in messages to test how far the program executed. It never gets to the actual process.Kill(); for some reason. Any ideas? thanks in advance

#2
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
First of all, post you complete solution so we can run... ahem, let our pcs die. :closedeyes:

#3
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
As requested

Attached Files


Edited by Victor, 13 April 2009 - 02:49 PM.


#4
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
Please post your complete code base so that we can run your code and figure out what is wrong :)

#5
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
I explained via PM. Now about the code. Is it possible that you search for "notepad" thing while the GetProcessesByName() method requires input like "notepad.exe" ?

EDIT: Ah, dang. Looks like a dead end. Sample code on MSDN is without extension. Process.GetProcessesByName Method (String) (System.Diagnostics)

Regards, :cool:
Arek Bulski

#6
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
Being new to C#, I wasn't aware I could search for process name instead of just specifying the names. How exactly would I be able to do that?

#7
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
Fixed the problem. When I fed the blacklist into the program, it looked for processes that it couldn't find because of how I specified. I just needed to lose the extensions, terminated processes flawlessly.

Basically, Arek was right I just wasn't sure what he was talking but I was tinkering and sort of stumbled onto what he meant.

Thank you for all your help (and patience) Arek

Attached revised blacklist for those curious few

Attached Files



#8
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
Finished program
Free File Hosting Made Simple - MediaFire

Edited by Victor, 13 April 2009 - 05:54 PM.
wrong link