Windows 7 UAC 自动更新应用程序
我们有一个应用程序套件,可以通过自主开发的“自动更新”应用程序进行更新。该应用程序基本上连接到我们的“更新服务器”并下载文件以覆盖、更新,甚至向我们的应用程序套件添加新功能/应用程序。但是,这对于 UAC 来说效果不佳。我们的自动更新应用程序是一个命令行 .NET 应用程序,通过 HKLM\Software\Microsoft\Windows\CurrentVersion\Run 注册表项启动。
我们遇到的问题是,当 UAC 打开时,我们的应用程序无法运行。它也不提示用户允许程序运行。我有什么选择来解决这个问题?
以下是不选项:
1. 关闭 UAC - 公司政策
2. 使用 ClickOnce - 不支持我们的需求(这就是我们自行开发的原因)
非常感谢。
We have an application suite that we update via a homegrown "Auto Update" application. This application basically connects to our "Updates server" and downloads files to overwrite, update, or even add new features/applications to our application suite. However, this does not work well with UAC. Our Auto Update application is a command line .NET application that is launched via HKLM\Software\Microsoft\Windows\CurrentVersion\Run registry key.
The problem that we have is when UAC is turned on our application doesn't run. Nor does it prompt users to allow the program to run. What are my options to work around this or solve the problem?
The following are not options:
1. Turn UAC off - Company Policy
2. Use ClickOnce - Doesn't support our needs (thats why we went homegrown)
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在应用程序清单中请求提升UAC。如果您指定 requireAdministrator,它将调用 UAC,除非计算机策略阻止 UAC 提示。
You can request UAC elevation in the application manifest. If you specify requireAdministrator, it will invoke UAC, unless machine policy prevents UAC prompts.
您在游戏中处于领先地位,因为您的更新程序是一个单独的 exe。除了按照 @Martin 的建议在其上放置清单之外,理想情况下您还可以更改主应用程序的 UI。启用显示“应用更新”的按钮/菜单项,或弹出一些显示“强制更新已准备就绪,单击“确定”继续”的模式 UI。然后在按钮或菜单项或模式 UI 的 OK 上,用盾牌装饰。这提醒用户他们将收到 UAC 提示。
如果没有这个,你的代码将正常工作,但他们会感到惊讶。他们正在使用该应用程序,监控核反应堆或批准费用账户或其他任何事情,然后突然 - 哎呀! - 屏幕变黑,他们收到提示 - 它上面有一个 exe 名称,但没有人读它,而且它可能无法解释太多。
这个未经请求的 UAC 提示很可能不会获得用户的同意。因此,改变你的用户界面来向他们解释是一个更好的方法。
You're ahead of the game because your updater is a separate exe. In addtion to putting a manifest on it as suggested by @Martin, ideally you would also change the UI of the main app. Either enable a button/menu item that said "apply updates" or pop up some modal UI that says "mandatory updates are ready, click OK to continue". Then on the button or menu item or the OK of the modal UI, decorate with a shield. This reminds the users they will be getting a UAC prompt.
Your code will work fine without this, but they will be startled. They're using the app, monitoring the nuclear reactor or approving expense accounts or whatever and suddenly - blam! - the screen goes black and they get a prompt - it has an exe name on it but nobody reads it and it might not explain much anyway.
There's a good chance this unsolicited UAC prompt will not get consent from the user. So changing your UI to explain it to them is a better way.
理想情况下,您将使用 MSI 作为安装程序/更新程序 - 它知道是否/如何提升。
您的另一个解决方案是使用管理权限
ShellExecute
您的更新程序:其中
RunAsAdmin
是知道如何执行进程并在进程中提升的代码:Ideally you would use MSI as your installer/updater - it knows if/how to elevate.
Your other solution is to
ShellExecute
your updater with administrative privelages:Where
RunAsAdmin
is code that knows how to execute a process and elevate in the process: