比 TerminateProcess 更友善的方法?

发布于 2024-11-16 04:02:01 字数 340 浏览 5 评论 0原文

我有一个备份应用程序,它将在备份之前关闭用户定义的正在运行的程序,以便可以在备份之前关闭并刷新打开的数据文件。备份完成后,它将重新启动列表中的程序。

我使用 Caption 和 PostMessage(AppHandle,WM_CLOSE,0,0); 获取窗口句柄没有问题。这适用于大多数应用程序,但不适用于在通知区域(系统托盘)中运行的应用程序。

目前我正在使用 TerminateProcess( 并且它适用于那些通知区域应用程序,但它会使文件保持打开状态,因为 Windows 会绕过任何关闭指令并猛击那些指令 吗

我已经苦苦寻找了很久,但找不到更好的方法来关闭通知区域应用程序,有人可以帮忙

I have a backup app that will close user-defined running programs before the backup so that open data files can be closed and flushed before the backup. After the backup is complete it restarts the programs in the list.

I have no problem getting the window Handle using the Caption and PostMessage(AppHandle,WM_CLOSE,0,0); That works fine for most apps, but not for ones running in the Notification Area (System Tray)

Currently I am using TerminateProcess( and it works for those Notification Area apps, but it leaves files open as Windows bypasses any Close instructions and just slams those apps down.

I have searched long and hard and I cannot find a nicer way to shut down Notification Area apps. Can anyone please help?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-11-23 04:02:01

为了优雅地关闭程序,您需要了解该程序期望如何关闭。如果关闭主窗口可以完成此操作,那么您需要知道如何识别“主”窗口。

程序不在通知区域“内”运行。他们在那里显示图标。任何带有通知图标的程序也必须有一个窗口(因为 shell 通过向窗口发送消息来告诉程序该图标已被单击)。即使窗口不可见,它仍然必须存在。如果您可以确定一些属性来标识与特定通知图标关联的窗口,那么您可以将其关闭。然而,并没有一套标准的属性可供寻找。每个程序都可以做不同的事情。

即使您找到了要查找的窗口,关闭它也可能不是程序期望的终止方式。它可能期望来自通知图标菜单的某个命令,或者程序显示的对话框发送的某些消息。

In order to close a program gracefully, you need to know something about how that program expects to be closed. If closing the main window accomplishes it, then you need to know how to recognize the "main" window.

Programs don't run "in" the notification area. They display icons there. Any program with a notification icon must also have a window (because the shell tells the program that the icon has been clicked by sending messages to the window). Even if the window isn't visible, it still must exist. If you can determine some set of properties that identify the window associated with a particular notification icon, then you could close it. There is no standard set of attributes to look for, though; each program can do it differently.

And even if you find the window you're looking for, closing it might not be the way the program expects to be terminated, either. It might expect a certain command from the notification icon's menu instead, or some message sent by a dialog box that the program displays.

我爱人 2024-11-23 04:02:01

如果您的应用程序在 Windows Vista 或 Windows 7 上运行,请不要关闭程序 - 而是使用 卷影复制服务,用于在文件仍在使用时访问文件快照。这就是 Windows 7 内置备份程序的作用。

如果您使用的是早期版本的 Windows,则没有万无一失的解决方案。如果程序有系统托盘图标,它也会有一个隐藏窗口,您可以尝试发送 WM_QUERYENDSESSIONWM_ENDSESSION 到它。但是,无法保证程序将关闭,并且如果它确实关闭,由于您可能绕过了其正常关闭过程的部分内容,因此它可能无法完成其正常清理。也可能有一些程序在根本没有关联的窗口的情况下运行。最好的方法可能是简单地注销用户,然后从服务进程执行备份。当然,您仍然会遇到与其他服务打开的文件共享问题......

If your application is running on Windows Vista or Windows 7, don't shut down programs - instead use the Volume Shadow Copy service to access a snapshot of the files while they are still in use. This is what the Windows 7 built-in backup program does.

If you're on an earlier version of Windows, there's no foolproof solution. If the program has a systray icon, it will have a hidden window as well, and you can try sending WM_QUERYENDSESSION and WM_ENDSESSION to it. However, there is no guarentee that the program will shut down, and if it does shut down, since you may be bypassing parts of its normal shutdown process, it may not complete its normal cleanup. There may also be programs running with no associated windows at all. The best approach would probably be to simply log off the user, and perform the backup from a service process. Of course, you'll still have sharing issues with files opened by other services...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文