1

In my application, I started a process say chrome via the command`

Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");

Now I want to close this current process. What should I code so as to close just this chrome application.

  • Simply [Kill()](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill(v=vs.110).aspx) the `Process` instance you get from `Process.Start()`? – Filburt Mar 02 '17 at 19:50
  • `Process.Start` is a function which returns a `Process`. Choose the appropriate method from [the documentation](https://msdn.microsoft.com/en-us/library/system.diagnostics.process_methods(v=vs.110).aspx) to close it. I suppose that the user might have opened more windows or tabs, seeing as it is a browser that you have started.. – Andrew Morton Mar 02 '17 at 19:52
  • 1
    @Filburt Kill might be a bit harsh: "Kill causes an abnormal process termination, and should be used only when necessary." CloseMainWindow seems more reasonable. – Andrew Morton Mar 02 '17 at 19:56
  • @AndrewMorton It did fit well in the comment context and should mainly serve to point the OP to MSDN. – Filburt Mar 02 '17 at 20:16
  • @Andrew Morton -s .CloseMainWindow() is much more elegant, should be posted as Answer. – CLS May 16 '19 at 12:20
  • @CLS Following the comments to the [answer by Anderson Pimentel](https://stackoverflow.com/a/42564807/1115360), which included CloseMainWindow, I am not sure what the question is. – Andrew Morton May 17 '19 at 08:01

1 Answers1

0

As pointed out on comments, just call the Kill() method on the instance returned by Process.Start('...').

var myProcess = Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");

//Do your stuff...

myProcess.Kill();

Also, take a look at MSDN about a (maybe) better way to terminate the process: CloseMainWindow.

EDIT:

To kill an arbitrary process take a look at this question.

Community
  • 1
  • 1
Anderson Pimentel
  • 5,086
  • 2
  • 32
  • 54