如何授予我的 C# 应用管理权限?清单文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1850768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 21:22:50  来源:igfitidea点击:

How to give my C# app administrative rights? manifest file

c#permissionsadminmanifestrights

提问by Oppermann

I'm having some trouble with my C# app that uses win32_networkingadapterconfig. The problem is that I can't use the altering functions in win32_networkingadapterconfig when I use the app on a user that dont have admin rights. I have tried to "run as administrator", but no luck. And I have tried to make a manifestfile with this content in the trustInfo part:

我的 C# 应用程序使用 win32_networkingadapterconfig 时遇到了一些问题。问题是当我在没有管理员权限的用户上使用该应用程序时,我无法使用 win32_networkingadapterconfig 中的更改功能。我试图“以管理员身份运行”,但没有运气。我尝试在 trustInfo 部分使用此内容制作清单文件:

<security>
  <applicationRequestMinimum>
    <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
    <defaultAssemblyRequest permissionSetReference="Custom" />
  </applicationRequestMinimum>
  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

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

  </requestedPrivileges>
</security>

Enable clickone security settings are set to full trust. What am I doing wrong ?

启用 clickone 安全设置设置为完全信任。我究竟做错了什么 ?

回答by Hans Passant

There's a "trustinfo" dangling in your snippet. Make it look like this:

您的代码段中有一个“trustinfo”悬空。让它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

回答by Robert MacLean

There are a number of possible issues which I have listed in the order I suspect is most likely to less likely.

有许多可能的问题,我按照我认为最有可能不太可能的顺序列出。

Possible Problem 1
What are your UAC settings? As detailed in Create and Embed an Application Manifest (UAC) if you have UAC disabled and you request administrator permissions the

可能的问题 1
您的 UAC 设置是什么?如创建和嵌入应用程序清单 (UAC) 中所述, 如果您禁用了 UAC 并请求管理员权限

Application might launch but will fail later

应用程序可能会启动但稍后会失败

Possible Problem 2
There could be something wrong else where in the manifest as the assembly information is required. Posting your whole manifest would help.

可能的问题 2
清单中的其他地方可能有错误,因为需要程序集信息。发布您的整个清单会有所帮助。

Possible Problem 3
You have added the applicationRequestMinimumnode which is not required for UAC escalation. It may be worth dropping that and trying again.

可能的问题 3
您添加了applicationRequestMinimumUAC 升级不需要的节点。可能值得放弃并重试。