在 Windows 服务中使用 SHFileOperation

发布于 2024-07-08 08:29:36 字数 137 浏览 8 评论 0原文

这是可能的,但是在 Windows 服务中使用 SHFileOperation 是否合适? shell32.dll 中的所有这些 SHxxx API 函数似乎都是根据用户级程序编写的。 我可以确定 SHFileOperation 永远不会显示 GUI 吗?

It's possible, but is it appropriate to use SHFileOperation within a Windows service? All those SHxxx API functions in shell32.dll seem to have been written with user level programs in mind. Can I be certain SHFileOperation won't display GUI ever?

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

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

发布评论

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

评论(4

以歌曲疗慰 2024-07-15 08:29:36

根据 SHFILEOPTSTRUCT 文档,您可以使用以下标志可防止出现任何 UI:

FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR

或(如果您的目标是 Windows Vista)FOF_NO_UI,与上面的相同。

查看Windows SDK中的ShellAPI.h头文件,针对FOF_NO_UI的注释说“根本不显示任何UI”,因此我认为这是可以的使用SHFileOperation。

According to the SHFILEOPTSTRUCT documentation, you can use the following flags to prevent any UI from appearing:

FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR

or (if you're targeting Windows Vista), FOF_NO_UI, which is the same as the above.

Looking in the ShellAPI.h header file in the Windows SDK, the comment against FOF_NO_UI says "don't display any UI at all", so from this I assume it's OK to use SHFileOperation.

ゃ懵逼小萝莉 2024-07-15 08:29:36

我想说,这并不是不合适或不建议的。 大多数 shell32 API 都是在编写时就基本了解它们将在交互式进程中使用。 我认为没有任何方法可以保证 SHFileOperation 永远不会显示 UI 组件。 事实上,如果您查看 IFileOperation(这是取代SHFileOperation的新Vista接口),它明确指出:

公开复制、移动、重命名、创建和删除 Shell 项的方法以及提供进度和错误对话框的方法。 该接口替代了SHFileOperation函数。

I would say, not it's not appropriate or advisable. Most of the shell32 APIs were written with a basic understanding that they would be used in interactive processes. I don't think there is any way you can guarantee that SHFileOperation will never display a UI component. In fact, if you look at IFileOperation (which is the new Vista interface that replaces SHFileOperation), it clearly states:

Exposes methods to copy, move, rename, create, and delete Shell items as well as methods to provide progress and error dialogs. This interface replaces the SHFileOperation function.

心如荒岛 2024-07-15 08:29:36

我必须同意:不合适或不建议。

使用 SHFileOperation 的主要原因是通过 UI 执行操作,和/或可逆的操作。 即,使用 SHFileOperation 删除文件会将文件放入回收站,而不是删除它们,从而允许当前交互用户取消删除或撤消所执行的操作。
由于服务在非交互式桌面上运行,因此没有人能够清除回收站。

I have to agree: not appropriate or advisable.

The prinicpal reason to use SHFileOperation is to perform operations with a UI, and/or which are reversable. I.e. using SHFileOperation to delete files is going to place the files in a recycle bin rather than deleting them allowing the current interactive user to undelete, or undo the operation performed.
As the services run on a non interactive desktop, no one will ever be able to clear that recycle bin out.

梦在深巷 2024-07-15 08:29:36

我也遇到了这个问题,并致力于在服务器和网络共享之间实现安全可靠的网络文件复制(大多数共享基于 CIFS / NetApp 文件管理器),并且 SHFileOperation 有时会失败。

现在开始使用 ROBOCOPY(默认情况下在 Vista/Server 2008 以上的所有 Microsoft 操作系统中可用),看起来确实很有趣且可靠。

这让我大开眼界:https://stackoverflow.com/a/1030752/559144

I had this issue as well and working at implementing a secure and reliable network file copy between servers and network shares ( most of these shares are CIFS / NetApp filer based ) and SHFileOperation fails from time to time.

now started using ROBOCOPY (available by default in all Microsoft OS from Vista/Server 2008 upwards) and really looks interesting and reliable.

this has opened my eyes: https://stackoverflow.com/a/1030752/559144

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