如何强制WPF应用程序在管理员模式下运行 [英] How to force a WPF application to run in Administrator mode

查看:499
本文介绍了如何强制WPF应用程序在管理员模式下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,可以访问Windows服务,本地计算机上的任务计划程序。
当我部署此WPF应用程序并在没有以管理员身份运行的情况下运行该应用程序时,该应用程序将失败,因为它无法访问本地计算机上的Windows服务和任务计划程序。如果我使用以管理员身份运行来运行它,则它可以正常工作。

I have an WPF application which access windows services, task schedulers on the local machine. When I deploy this WPF application and run it without "Run as Administrator" , it fails as it is not able to access the windows services and task schedulers on the local machine. If I run it with "Run as Administrator", it works correctly.

当应用程序在生产环境中部署时,如何使我的应用程序默认在管理员模式下运行?

How do I make my application by default run in admin mode when it is deployed in production?

推荐答案

您需要添加 app.manifest 。将 requestedExecutionLevel
asInvoker 更改为 requireAdministrator 。您可以使用添加文件对话框创建一个新的清单,将其更改为需要管理员。确保您的项目设置也设置为使用该清单。

You need to add an app.manifest. Change the requestedExecutionLevel from asInvoker to requireAdministrator. You can create a new manifest by using the add file dialog, change it to require administrator. Make sure that your project settings are set to use that manifest as well. This will allow you to simply double click the application and it will automatically prompt for elevation if it isn't already.

请参见此处以获取更多文档:

See here for more documentation:

http://msdn.microsoft.com/en-us/ library / bb756929.aspx

编辑:
对于它的价值,本文使用VS 2005和 mt。 exe 嵌入清单。如果您使用的是Visual Studio 2008+,它是内置的。只需打开Project的属性,然后在应用程序选项卡上选择清单即可。

For what it's worth, the article uses VS 2005 and using mt.exe to embed the manifest. if you are using Visual studio 2008+, this is built in. Simply open the properties of your Project, and on the "Application" tab you can select the manifest.

这篇关于如何强制WPF应用程序在管理员模式下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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