简体   繁体   English

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

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

I'm having some trouble with my C# app that uses win32_networkingadapterconfig. 我的使用win32_networkingadapterconfig的C#应用​​程序遇到了一些麻烦。 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. 问题是,当我对没有管理员权限的用户使用应用程序时,无法在win32_networkingadapterconfig中使用更改功能。 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: 我尝试在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. 启用clickone安全设置被设置为完全信任。 What am I doing wrong ? 我究竟做错了什么 ?

There's a "trustinfo" dangling in your snippet. 您的摘要中有一个“ trustinfo”。 Make it look like this: 使它看起来像这样:

<?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>

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 可能的问题1
What are your UAC settings? 您的UAC设置是什么? As detailed in Create and Embed an Application Manifest (UAC) if you have UAC disabled and you request administrator permissions the 创建和嵌入应用程序清单(UAC)中所述,如果禁用了UAC并要求管理员权限,则

Application might launch but will fail later 应用程序可能会启动,但稍后会失败

Possible Problem 2 可能的问题2
There could be something wrong else where in the manifest as the assembly information is required. 清单中需要组装信息的其他地方可能有问题。 Posting your whole manifest would help. 发布整个清单将有所帮助。

Possible Problem 3 可能的问题3
You have added the applicationRequestMinimum node which is not required for UAC escalation. 您已经添加了UAC升级不需要的applicationRequestMinimum节点。 It may be worth dropping that and trying again. 可能需要删除它然后再试一次。

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

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