自更新应用程序和UAC - 最佳实施

发布于 2024-12-10 15:21:53 字数 288 浏览 0 评论 0原文

我正在寻求一些指导以使自更新应用程序符合 UAC 要求。 我有一个应用程序,可以在启动时检查更新,然后自动下载任何新的二进制文件并将其替换为较新的二进制文件。 问题在于,在 Windows 7 下,任何写入 Program Files 文件夹的应用程序似乎都需要管理员 UAC 提升。 我们已将代码添加到应用程序清单中,以自动请求 UAC 提升以使更新生效,但这当然不是最佳解决方案,因为如果用户启用了 UAC 提示,用户将看到管理员提示。 我可以选择哪些选项来实现 UAC 合规性并仍保持应用程序的自我更新属性?

谢谢,

汤姆

I'm seeking some guidance to make a self-updating application UAC compliant.
I have an application that checks for updates on launch and then automatically downloads any new binaries and replaces them with newer ones.
The problem with this is that under Windows 7, any application that writes to the Program Files folder, seems to require Admin UAC elevation.
We've added code to the application manifest to automatically request UAC elevation for the updates to work but naturally this is not an optimal solution as users will see the Admin prompt if users have the UAC prompts enabled.
What are my options to be UAC compliant and still maintain the self-updating properties of the application?

Thanks,

Tom

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

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

发布评论

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

评论(4

夏日落 2024-12-17 15:21:53

基本上,如果您想安装到 Program Files,那么您将需要显示 UAC 提示。

当然,您可以修改安装文件夹的访问控制设置(即您在资源管理器属性对话框的安全页面中设置的内容)以使其可写。但这将违背所有已知的最佳实践。我不提倡这样做。

一种替代方法是像 Chrome 那样安装并安装在用户配置文件下。这种方法也有缺点。这样做需要计算机上的每个用户都安装该软件,然后每个用户都需要单独更新。您还会失去 UAC 提供的一些保护。

Basically, if you want to install to Program Files then you will need to show the UAC prompts.

Of course, you could modify the access control settings (i.e. what you set in the security page of Explorer properties dialog) for your install folder to make it writeable. But that would be against all known best practice. I would not advocate it.

One alternative is to do what Chrome does and install under the user profile. There are downsides to this approach. Doing it this way requires every user on the machine to install the software, and then each user would need to update individually. You also lose some of the protection that UAC affords.

无尽的现实 2024-12-17 15:21:53

除了大卫所说的之外,您还可以安装一个后台服务来为您管理更新。该服务将接收来自您的应用程序的更新请求并管理将文件写入安装目录。从用户的角度来看,这将是完全无缝的,没有 UAC 提示(除了初始安装时的提示)。

In addition to what David said, you could also install a background service which manages updates for you. The service would receive update requests from your application and manage writing files to the install directory. From the user's perspective, it would be entirely seamless with no UAC prompts (except for one, at the time of initial install).

叶落知秋 2024-12-17 15:21:53

您不需要管理员权限来运行您的应用程序,因此您的应用程序清单应包含 asInvoker 级别。否则有限的用户将无法运行您的应用程序,这当然不是您想要的。

David 提到 Firefox,这就是它自动执行的方式更新。它不需要管理员权限即可运行。 Firefox 在后台下载更新并将其保存在硬盘上。下次用户启动 Firefox 时,它会看到更新已准备好安装,并启动较新版本的安装程序。安装程序必须以提升权限运行,这就是为什么用户会看到 UAC 提示提升权限的原因。更新完成后,Firefox 将再次以非提升状态启动。

棘手的部分是更新完成后以非提升方式启动 Firefox。我不建议使用技巧从提升的进程启动非提升的进程。您应该使用常规用户安全令牌保留一个进程。我不知道 Firefox 如何处理它,但最简单的方法是:启动非提升的更新程序(在清单中用 asInvoker 标记它),然后更新程序重新启动,使用 ShellExecute 提升 函数和 runas 动词。当提升的进程完成时,它会启动更新的应用程序。

You should not require administrator privileges to run your application, therefore your application manifest should contain asInvoker level. Otherwise limited users would not be able to run your application, surely this is not what you want.

David mentioned Firefox, this is how it auto-updates. It does not require administrator privileges to run. Firefox downloads update in the background and saves it on the hard disk. The next time user starts Firefox, it sees an update is ready to install and starts the installer of the newer version. Installer has to be run elevated, that's why users see UAC prompt for elevation. When update is done, Firefox starts again non-elevated.

The tricky part is to start Firefox non-elevated when update completes. I would not recommend using tricks to start a non-elevated process from an elevated one. You should keep one process with regular user security token. I don't know how Firefox handles it, yet the simplest way would be: start updater non-elevated (mark it with asInvoker in the manifest), then the updater restarts itself elevated with ShellExecute function and runas verb. When the elevated process completes, it starts the updated application.

爱的故事 2024-12-17 15:21:53

我真的很喜欢谷歌的做法。

Google 现在使用作为本地系统运行的 Google 更新服务来更新 Chrome 及其其他产品。 UAC 在安装时触发,然后再也不会触发。应用程序安装到 Program Files 中,这解决了使用 AppData 的两个问题:第一,许多企业阻止从 AppData 启动可执行文件;第二,许多企业阻止从 AppData 启动可执行文件。更重要的是,一台计算机上的多个用户都必须在该计算机上的 AppData 中进行单独的安装。

当有新版本可用时,更新程序服务会在基本目录下静默添加一个版本文件夹(例如,Program Files\Google\Chrome\Application\45.0.2454.93,然后是 Program Files\Google\Chrome\Application\45.0.93)。 2454.101)。 Chrome 启动器仅从最高版本文件夹运行 Chrome 应用程序。

I really like how Google does this.

Google now updates Chrome and its other products using a Google Update Service running as Local System. UAC is triggered at install time, and then never again. Applications are installed to Program Files, which defeats the twin problems of using AppData: first, that many enterprises block executables launching from AppData; and, more importantly, that multiple users on a machine would each have to make a separate installation into AppData on that machine.

When a new version is available, the Updater Service silently adds a version folder under a base directory (e.g., Program Files\Google\Chrome\Application\45.0.2454.93, and then later, Program Files\Google\Chrome\Application\45.0.2454.101). The Chrome launcher simply runs the Chrome application from the highest versioned folder.

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