.NET - 启用 UAC 时应用程序如何能够自我更新(Windows7/Vista)?
场景如下:
我编写了一个应用程序,并从 Visual Studio 安装程序项目创建了一个安装程序(我生成了一个 MSI 文件)。我以管理员身份将该应用程序安装到 Program Files 目录中。
当用户使用该应用程序时,我希望它能够自动更新(而不打扰管理员)。现在,Windows 7 和 Windows Vista 具有 UAC 来保护 Program Files 目录。所以,我不太确定从这里该去哪里。
我想我在某处读到 ClickOnce 能够安装应用程序的更新,而无需打扰用户的管理权限。
- 有没有可以帮助自动更新的应用程序?
- 如果存在这样的应用程序,它们如何能够绕过提升的权限?基本上,是否可以以某种方式复制这些应用程序在 .NET (C#) 中的功能?
我真的只是希望有一种简单的方法来使用 MSI 文件进行静默更新,因为我不希望普通用户具有管理访问权限,也不希望管理员被这项任务所困扰。此外,显然事情不能被硬编码,因为用户名和密码很容易改变。
Here's the scenario:
I wrote an application and created an installer from the Visual Studio Installer project (I produced an MSI file). I installed the application into the Program Files directory as an administrator.
When a user uses the application I was hoping it would be able to auto-update itself (without bothering the administrators). Now, Windows 7 and Windows Vista have UAC to protect the Program Files directory. So, I'm not really sure where to go from here.
I think I read somewhere that ClickOnce is able to install updates to the application without bothering the user for administrative permissions.
- Are there any apps out there that can assist with auto-update?
- If there are apps out there like that, how are they able to bypass the elevated permissions? Basically, wouldn't it be possible to replicate what these applications do in .NET (C#) somehow?
I'm really just hoping for an easy way to use an MSI file to do a silent update because I don't want normal users to have administrative access and I don't want administrators to be bothered with this task. Also, obviously things can't be hardcoded in because usernames and passwords could easily change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果安装程序和更新包使用相同的数字证书进行签名,则可以使用 MSI 更新应用程序,而无需管理员权限。
这称为 UAC 修补。 此是 MSDN 上的相关页面。
It is possible to update your application using MSI without requiring Admin privileges IF the installer and update package are signed using the same digital certificate.
This is called UAC patching. This is the relevant page on MSDN.
您可以做的一件事肯定会起作用,那就是创建一个作为本地系统运行的更新服务。这个肯定会绕过UAC。
另一种选择(因为安装服务可能被认为过于侵入性)是安排任务,再次通过 W7 任务调度程序作为本地系统运行。
在任何一种情况下,都必须在安装期间完成此操作,否则 UAC 将再次被触发。
编辑:我只是想到了另一种处理方式:你可以用 Chrome 风格来实现。不要将任何内容安装到程序文件中,将所有应用程序二进制文件和数据保存在用户文件夹中。这样你就可以随意升级,只需用户级权限,不会触发UAC
One thing you could do that would definitely work is create an update service running as localsystem. This one would bypass UAC for sure.
Another option (since installing a service might be seen as too invasive) is to schedule a task, again running as a localsystem via W7 task scheduler.
In either scenario, this must be done during install, otherwise UAC will get triggered again.
EDIT: I just thought of another way of handling it: you can do it Chrome style. Don't install anything into program files, keep all application binaries and data in user folder. This way you could upgrade at will with only user-level permissions and no UAC triggered
ClickOnce 不会将您的应用程序安装到程序文件中(如果有人稍后需要尝试找到该文件夹,这会非常烦人),这就是它避免这种情况的方法。没有任何方法可以“绕过”UAC,我建议您这样做:使用 icacls 和 takeown 将安装文件夹的所有权授予本地用户,这就是 Steam 允许自己将游戏安装到其文件夹中的做法。
编辑:您还可以使用
SetSecurityInfo
在代码中向本地用户授予所有权。ClickOnce doesn't install your application to program files (which is very annoying if anyone needs to try and find the folder later) which is how it avoids it. There aren't any ways to 'bypass' UAC, this is what I recommend you do: give ownership of your install folder to the local user with icacls and takeown, which is what Steam does to allow itself to install your games into it's folder.
Edit: You can also give ownership to the local user in code with
SetSecurityInfo
.