简体   繁体   中英

How to ask to restart firefox?

I have created a c++ program that install also a firefox extension. So, to get this extension works, he need to restart firefox.

So, how can I ask to restart firefox while the user is using it ?

This kind of looks like a duplicate to this question: winapi - How can I get a process handle by its name in C++ . Essentially, what you'd be looking to do is "find" the process "firefox.exe" (in place of "target.exe") and if finding it is successful, you put up a warning dialogue box to close firefox and re-open. If not, you just continue with the install or whatever. Hope this helped!

Find the main window of Firefox using its caption. I guess Firefox appends the title of the current page to the caption of the main window, so FindWindow is not enough. Try to enumerate top-level windows using EnumWindows , and find the one containing "Mozilla Firefox" in the caption. If you have the window handle, send a WM_CLOSE message to it (use PostMessage which waits for the target window to process the message), and wait for it to disappear. You may get a popup, find and close it the same way. If the main Firefox window is still open after a few seconds (try to find it repeatedly), you may call TerminateProcess (you will need GetWindowThreadProcessId and OpenProcess for this). When the window is closed, restart Firefox by calling CreateProcess . (There are lots of examples for all these API functions on the Web.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM