使用管理提升 WIX 运行 WPF 应用程序
我写了一个WPF应用程序。 当它安装在客户端计算机上时,系统会提示他们输入用户名和密码,以便他们拥有使用该应用程序的管理员权限。
我需要管理员权限,因为我的应用程序打开端口并将文件写入文件系统。
是否可以允许任何用户在不提示输入管理员用户名和密码的情况下运行应用程序,并提升应用程序以管理员权限运行?
谢谢
I have written a WPF application.
When it is installed on client machines, they are prompted for a username and password so that they have administrator privileges to use the application.
I need administrator privileges because my application opens ports and writes files to the file system.
Is it possible to allow any user to run the application without being prompted for an administrator username and password and to elevate the application to run with administrator privleges?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的应用程序安装时,如果安装程序已标记为管理员执行,则会提示管理员权限。通常仅当您想要安装到可供多个用户使用的位置(例如在 Program Files 文件夹层次结构中)时才需要执行此操作。默认情况下,MSI 将引发 UAC 提示,但很容易 使用 WIX 创建一个不会引发 UAC 提示的 MSI。
当您的应用程序运行时(由没有管理员权限的用户),如果应用程序本身已被标记为管理员执行,它将要求管理员权限。这部分由您控制,但可以被客户端计算机上的用户覆盖。
只要运行应用程序的用户有权访问这些文件夹,写入文件系统文件夹的应用程序就不需要管理员权限。通常,您可以通过写入每个用户都可以访问的位置来完成此操作。
但是,我认为,如果应用程序执行的操作不仅仅是查询统计信息,那么打开端口确实需要管理员权限。
如果您的应用程序确实需要管理员权限才能运行,并且您不希望非管理员用户在程序执行期间看到UAC提示,那么我建议您将您的应用程序分为两部分。
第一部分是在特权用户(例如 LocalSystem)下运行的 Windows 服务,并配置为与桌面程序交互。该服务执行所有与管理相关的任务,并且需要由请求管理权限的安装程序进行设置。
第二部分是不执行任何特权操作的 WPF 程序。如果您将此 WPF 程序标记为不需要提升,则最终用户在运行它时将永远不会看到 UAC 提示,因为所有特权工作都是由始终运行的服务完成的。
When your app is installed, it will prompt for admin rights if the installation program has been marked for admin execution. This is normally only required if you want to install to a location available to multiple users, such as within the Program Files folder hierarchy. An MSI will raise a UAC prompt by default, but it's easy to make an MSI with WIX that doesn't raise a UAC prompt.
When your app is run (by a user without admin rights), it will ask for admin rights if the app itself has been marked for admin execution. This is partly under your control, but can overridden by users on the client machine.
An app that writes to file system folders doesn't require admin rights as long as the user running the app has permission to those folders. Generally you can make this work by writing to a location that's accessible to each user.
However, I believe that opening a port does need admin rights if the app is doing anything more than querying statistical information.
If your app does need admin rights to run, and you don't want your non-admin users to see a UAC prompt during program execution, then I suggest you divide your app into 2 parts.
The first part is a Windows service that runs under a privileged user such as LocalSystem and is configured to interact with desktop programs. This service does all of the admin-related tasks, and will need to be setup by an installer that requests admin rights.
The second part is the WPF program that doesn't do anything privileged. If you mark this WPF program as not needing elevation, your end-users will never see a UAC prompt when running it, because all the privileged work is being done by a service that's always running.