如何使 WPF 应用程序以用户身份运行,启动更新程序提示升级权限,然后让更新程序在再次以用户身份更新后运行 WPF?
两个申请; WPF 应用程序和控制台更新程序。 WPF 由用户检查是否有要执行的更新启动,启动带有升级提示的更新程序,以便它可以替换 WPF 应用程序(和支持文件)。更新程序替换文件后希望它以原始用户身份启动 WPF 应用程序。如果有人想知道我必须升级更新程序的权限,因为它正在替换安装 WPF 应用程序的 Program Files 文件夹下的文件。
Two applications; WPF Application and Console Updater. WPF is launched by User checks to see if there is an Update to be performed, launches Updater with escalation prompt so that it can replace WPF Application(and supporting files). After Updater replaces files want it to start the WPF Application as the original User. In case anyone wants to know I had to escalate privileges on Updater because it was replacing files under Program Files folder where the WPF Application is installed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Process 类以管理员身份启动更新程序。这将显示 UAC,用户可以决定是否允许更新程序运行。然后您可以退出原来的程序。更新结束后,在没有管理员权限的情况下执行相同的操作以再次启动软件。
如何启动新进程没有管理员权限的进程是否具有管理员权限?
我不喜欢这些答案,但它们会起作用。最好使用常规 Windows 安装程序技术(Wix 或许多其他软件包之一)来部署更新,并作为该过程的一部分,在升级后重新启动原始程序。这是您在大多数软件中看到的方法。无论如何,您都需要编写一个安装程序来将软件安装到计算机上,只需在最后添加一个步骤来启动软件即可。
Launch the updater program as administrator using the Process class. This will present the UAC and the user can decide if they will allow the updater to run. You can then exit your original program. At the end of your update, do the same thing without administrator privileges to launch your software again.
How to start a new process without administrator privileges from a process with administrator privileges?
I don't like any of these answers, but they will work. It would be better to deploy your updates using regular windows installer techniques (Wix, or one of the many other packages), and as part of that process, have it restart the original program after upgrading it. This is the approach you see in most software. You're going to need to write an installer to get the software on the computer anyway, just add a step at the end to start the software.