How to properly close an application remotely

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
I'm using SendMessage with WM_CLOSE to close some Firefox windows. I have several Firefox windows open concurrently and it's easier to do it like this than by closing the windows manually. But, while SendMessage closes the windows, it doesn't actually seem to shut Firefox down. Firefox continues to be shown in the Task Manager. This leads to errors when I want to reopen Firefox.

How do I ensure that Firefox closes when I close all of its windows?
 
Hmm, now it's stopped working. Here's my code:

Code:
SendMessage(hwnd, WM_CLOSE,0,0)
SendMessage(hwnd, WM_QUIT,0,0)

I have several Firefox windows running and do this for every one that I close. If I've closed them all, and then want to open a new window, I often get a message that Firefox is still running and that I must close the existing process before I open a new one. When I look in the Task Manager it's still showing even though there are no windows visible.

Any ideas?
 
I don't know if this could be related to your issue, but sometimes when I close firefox it keeps running in the background for a while. I see this behavior on multiple machines. I assume it's doing some some house-keeping. Eventually it does close itself.
 
Thanks. If it wants to do that it's OK, I don't mind waiting. But is there any way of checking in code whether or not it has closed, so that I don't reopen it while it's still running and get the errors that I'm getting?
 
You could periodically enumerate the processes and see if firefox.exe is among them. I think the Process class has a method named GetProcesses.
 
You could periodically enumerate the processes and see if firefox.exe is among them. I think the Process class has a method named GetProcesses.

Thanks. It in fact has a method called GetProcessesByName, so this is all quite easy to do. If I've closed all windows and the process is still there, I just call its Kill method.
 
Back
Top