Kinder way than TerminateProcess?

I have a backup application that closes user running programs before backing up so that open data files can be closed and reset before backup. After the backup is complete, it restarts the programs in the list.

I have no problem getting a Handle window using Caption and PostMessage (AppHandle, WM_CLOSE, 0,0); This is great for most applications, but not for those who work in the notification area (system tray)

I am currently using TerminateProcess (and it works for those Notification Area applications, but it leaves the files open as Windows bypasses any Close statements and simply deletes those applications.

I searched long and hard, and I cannot find a better way to close the notification area applications. Can anybody help?

thanks

+7
source share
2 answers

To finish the program gracefully, you need to know something about how this program expects closure. If closing the main window performs it, then you need to know how to recognize the "main" window.

Programs do not start "in" the notification area. Icons are displayed there. Any notification program should also have a window (since the shell tells the program that the icon was clicked by sending messages to the window). Even if the window is not visible, it should still exist. If you can define a set of properties that identify the window associated with a particular notification icon, then you can close it. However, there is no standard set of attributes to search for; each program can do it differently.

And even if you find the window you are looking for, closing it may not be the same as the program is also waiting for completion. Instead, he can expect a specific command from the notification icon menu or some message sent by the dialog box displayed by the program.

+8
source

If your application runs on Windows Vista or Windows 7, do not close programs - instead, use the shadow copy service of tones to access snapshot files while they are still in use. This is what the built-in Windows 7 backup program does.

If you are using an earlier version of Windows, there is no reliable solution. If the program has a systray icon, it will also have a hidden window, and you can try sending WM_QUERYENDSESSION and WM_ENDSESSION . However, there is no guarantee that the program will shut down, and if it shuts down, since you can bypass parts of your normal shutdown process, it may not complete the usual cleanup. Programs can also be run without related windows. The best approach would probably be to simply log out and back up from the maintenance process. Of course, you will still have problems sharing files opened by other services ...

+2
source

All Articles