需要提升权限而不弹出UAC

发布于 2024-10-04 04:41:15 字数 358 浏览 4 评论 0原文

我有一个应用程序,它是另一个应用程序(我的主应用程序)的启动器。启动器会转到 FTP 服务器,下载更新并安装它们。但是,更新可执行文件需要将一些 DLL 和 EXE 复制到主应用程序的安装目录(位于 Program Files 中)。因此,我目前需要提升更新者的权限。

这是一个问题,因为我的应用程序在启动时启动,并且通常只会加载到系统托盘(该应用程序与 Messenger/Skype 相当)。如果我在尝试“静默”更新应用程序时开始在屏幕上弹出 UAC 警告,那么它就不再那么安静了。

我现在看到避免该问题的唯一方法是授予所有用户对程序文件安装目录的权限,但我不愿意这样做。还有其他想法吗?

我使用的是 Windows 7,应用程序是用 C# 编写的。

I have an application which is a launcher for another application (my main one). The launcher goes to an FTP server, downloads updates and installs them. However, the update executable needs to copy some DLLs and EXEs to the installation directory of the main application, which is in Program Files. Because of that, I currently need to elevate the rights of the updater.

This is a problem because my application starts on boot, and in general will simply load to the system tray (the application is comparable to messenger/skype). If I start popping UAC warnings on the screen while trying to "silently" update the application, it's not so silent any more.

The only way I see right now to avoid the problem is to give all users permissions to the program files installation directory, but I am reluctant to do that. Any other ideas?

I'm using Windows 7, and the applications are in C#.

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

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

发布评论

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

评论(3

素食主义者 2024-10-11 04:41:15

这样做会违反用户访问控制的基本原则。

根据设计,无法在避免提示的同时提升权限。如果有办法做到这一点,UAC 就变得毫无用处了。


话虽如此,您可以尝试围绕这个问题进行设计。您可能需要考虑创建一个执行更新的 Windows 服务,而不是使您的程序成为启动/系统托盘应用程序。这可以在启动时以管理员身份运行(而不是登录),并且它已经以提升的权限运行。

如果您需要系统托盘应用程序,它可能是与服务“对话”的单独应用程序。

Doing so would violate the basic principle of User Access Control.

There is no way to elevate permissions while avoiding the prompts, by design. If there was a way to do this, UAC would become useless.


That being said, you could try to design around the issue. Instead of making your program a startup/system tray application, you may want to consider making a windows service that does the update. This could run as an administrator on boot (instead of login), and it would already run with elevated permissions.

If you need a system tray application, it could be a separate app that "talks" to the service.

jJeQQOZ5 2024-10-11 04:41:15

UAC 的全部要点是,未经用户批准,应用程序不能进行特权更改。也许您可以简单地让用户知道有可用更新,然后等待他们要求更新(此时将出现 UAC 提示,因为许多应用程序会更新),而不是尝试自动更新您的应用程序这边走)。

The whole point of UAC is that apps can't make priveleged changes without the user's approval. Rather than attempting to auto-update your app, perhaps you could simply let the user know that an update is available, and wait for them to ask for it to be updated (at which point the UAC prompt will be expected, as many apps update this way).

回梦 2024-10-11 04:41:15

我对已接受的答案投了赞成票,因为它正确的,但是,有时我们确实需要吃掉我们的蛋糕并拥有它。

我发现这个工具在批处理文件或启动时工作得很好:

https://github.com/alexey- gusarov/elevate

可以通过 Chocolatey 安装:

choco install elevate

I upvoted the accepted answer, because it is the correct one, but, sometimes we do need to eat our cake and have it too.

I found this tool to work beautifully from batch files or from startup:

https://github.com/alexey-gusarov/elevate

Can be installed via chocolatey:

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