Can any one tell me how can I close .exe file on button click using c#. I've got an idea of how to run .exe file on button click using c# as follows:
string str = @"C:\windows\system32\notepad.exe";
process.StartInfo.FileName = str;
process.Start();
But can anyone tell me how to close .exe application on button click in c#?
I think you want to call CloseMainWindow()
on the Process
. This is analogous to clicking on the close button of the window, so it may not actually close the application.
For example, if the user edited some text in the window, but didn't save it, this will show the “Do you want to save your changes?” dialog.
If you want to really close the application, no matter what, you can use Kill()
. This may cause loss of data (the edits to the file won't be saved), but that may not be a problem for you.
You should write under your button click something like this:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
This will close your current window, if its MDI child window
. Else it will close the application (assuming you got only one window open).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With