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...

1
  • 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? Jul 7, 2014 at 21:37

2 Answers 2

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

2
  • no I mean that when I start a process it gets the actual starting process and kills it. So the program should detect itselfs the starting process. Jul 8, 2014 at 11:33
  • not sure what do you mean Jul 8, 2014 at 12:19
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.