Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close a window from a different process

I have a c# application which I want to instruct to shutdown nicely, from a different process. I also want to be able to ask it to open its main window. I have a reference to its main window handle.

I know I can do it using elaborate schemes such as remoting or WCF. the question is can I do it using simpler mechanisms such as window messages, or the OnClose event handlers of the window in the c# application

like image 519
Aviad Rozenhek Avatar asked Dec 08 '10 13:12

Aviad Rozenhek


People also ask

How do I close a Windows system?

ALT+F4. System menu | Close. Close button.

How do I close a window using jquery?

$(element). click(function(){ window. close(); });


2 Answers

Pinvoke SendMessage() to send the WM_CLOSE message to the app's main window. Asking it to open its main window is probably going to be quite difficult, you cannot obtain the window handle until the window is created. Process.Start() would be the normal way.

A low cost alternative to WCF and superior to pinvoke is a named pipe or a socket to interface with the app. This requires being able to modify the source code of the app.

like image 181
Hans Passant Avatar answered Oct 27 '22 00:10

Hans Passant


Process.CloseMainWindow

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.closemainwindow.aspx

like image 30
Madhur Ahuja Avatar answered Oct 26 '22 23:10

Madhur Ahuja