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.
You can try to define a window handle using the Process class and send a WM_CLOSE message to the window.
Process
WM_CLOSE
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(); } } }