0

I want to get the starting process, I mean when I start as example notepad I want to get the process name(in my case: notepad.exe) and I want to kill it then. But I don't want to kill all running processes only the one I started at least.

Hope you understand what I mean. If not I will explain it more carefully with pictures...

  • 2
    Are you using Process.Start? You should already have a handle to kill it with if so. Could you post the code that starts the process? – BradleyDotNET Jul 07 '14 at 21:37

2 Answers2

2

You can use Killmethod from the Process class.

First start your process:

var pr =  Process.Start("IExplore.exe");

and then you can do:

pr.Kill();

You can read more here

Rafal Spacjer
  • 4,838
  • 2
  • 26
  • 34
1

Using Process.Start, you get back the process object, which has a Process.Kill method:

Process myNotepadProcess = Process.Start("notepad.exe")

myNotepadProcess.Kill();
myNotepadProcess.WaitForExit();

The Kill method executes asynchronously. After calling the Kill method, call the WaitForExit method to wait for the process to exit, or check the HasExited property to determine if the process has exited.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321