使用管理海拔WIX运行WPF应用程序 [英] Run WPF Application with administration elevation WIX

查看:107
本文介绍了使用管理海拔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?

谢谢

推荐答案

在安装您的应用程序后,如果已将 installation 程序标记为执行管理员,它将提示输入管理员权限.通常只有在您想要安装到可供多个用户使用的位置(例如在Program Files文件夹层次结构中)时,才需要这样做. MSI默认会提示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.

运行您的应用程序(由没有管理员权限的用户)运行时,如果 app 本身已标记为要执行管理员,它将询问管理员权限.这部分由您控制,但可以由客户端计算机上的用户覆盖.

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.

如果您的应用程序确实需要管理员权限才能运行,并且您不希望非管理员用户在程序执行过程中看到UAC提示,那么建议您将应用程序分为两部分.

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.

第一部分是Windows服务,该服务在特权用​​户(如LocalSystem)下运行,并配置为与桌面程序进行交互.该服务执行所有与管理员相关的任务,并且需要由请求管理员权限的安装程序来设置.

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.

第二部分是不执行任何特权的WPF程序.如果将此WPF程序标记为不需要提升,则最终用户在运行该程序时将永远不会看到UAC提示,因为所有特权工作都是由始终运行的服务完成的.

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.

这篇关于使用管理海拔WIX运行WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆