I need to open Firefox from my console app, do stuff with it, and then shut it down a few minutes later.
I'm using Process.Start("firefox.exe", "myurl"); to open firefox, which isn't a problem. The issue is with closing it.
The CloseMainWindow() function usually works, but it doesn't work if firefox has a modal window open (like a "download failed" message box). In this case, I can call Kill() on the process, however this seems dirty.
Also, if I call Kill() on the process, then the next time firefox opens there's a "session restore" tab open, which isn't cool. I could try to disable the session restore functionality, which would get around that issue. However, I'm still concerned that killing ffx like that could cause other problems.
Does anyone know a good way of doing this? Is the "cleanest" way to try and pinvoke to get the modal window handle, close that, and then retry CloseMainWindow()?