简体   繁体   English

C#应用程序未以管理特权运行

[英]C# Application not running with administrative privilege

I am running an application that should be run as administrative right but after adding manifest file give below application still not required to run as administrator. 我正在运行一个应以管理权限运行的应用程序,但添加清单文件后,仍然不需要以管理员身份运行以下应用程序。 The release and debugged executable work but while coding and debugging it does not required administrative privilege. 发行版和调试的可执行文件可以工作,但是在进行编码和调试时,不需要管理特权。 Kindly sort this out. 请解决这个问题。

Already tried these two line of code: 已经尝试了这两行代码:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

and

<requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

This is a limitation imposed by using a debugger, the program you start inherits the security token of Visual Studio. 这是使用调试器施加的限制,您启动的程序将继承Visual Studio的安全令牌。 Sounds like you are using an older version, starting with VS2013 you now get a reminder about this issue: 听起来您使用的是旧版本,从VS2013开始,现在您会得到有关此问题的提醒:

在此处输入图片说明

Which tells you what to do, "restart Visual Studio as an administrator". 告诉您该怎么做,“以管理员身份重新启动Visual Studio”。 Right-click its shortcut and select "Run as Administrator". 右键单击其快捷方式,然后选择“以管理员身份运行”。 Acknowledge the UAC prompt you get and reload your solution. 确认UAC提示您获取并重新加载解决方案。 Your program now automatically runs elevated as well, note that you do not get the UAC prompt when you press F5. 您的程序现在也将自动提升运行,请注意,按F5键时不会出现UAC提示。 You need to test if your manifest is effective separately. 您需要测试清单是否单独有效。

Another noteworthy detail about this quirk is that there are a bunch of Nuget packages around that only run correctly when VS runs elevated. 关于此怪癖的另一个值得注意的细节是,周围只有一堆Nuget程序包,它们仅在VS提升运行时才能正确运行。 And fail to work in a very hard to diagnose way, you don't get an error message when its install script fails to add a post-build event. 并且无法以非常难以诊断的方式工作,当其安装脚本未能添加构建后事件时,您不会收到错误消息。 Adding several gray hairs to the top of my head. 在我的头顶上增加几根白发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM