How to safely close Google Chrome programmatically

How can I safely close google chrome through C #? I can kill the chrome process, but in this case, Google Chrome will report appcrash the next time it starts.

+7
source share
2 answers

You can try to define a window handle using the Process class and send a WM_CLOSE message to the window.

+2
source

You can use the little-known user interface automation API , for example:

 static void CloseAllChromeBrowsers() { foreach (Process process in Process.GetProcessesByName("chrome")) { if (process.MainWindowHandle == IntPtr.Zero) // some have no UI continue; AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle); if (element != null) { ((WindowPattern)element.GetCurrentPattern(WindowPattern.Pattern)).Close(); } } } 
+9
source

All Articles