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

2

0

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:

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

Distraint answered 5/12, 2009 at 1:32 Comment(2)
ClickOnce applications don't support administrator level elevation.Sheng
However, I have the same problem with a standalone EXE and it also doesn't elevate.Sheng
W
4

There's a "trustinfo" dangling in your snippet. 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>
Wongawonga answered 5/12, 2009 at 1:42 Comment(3)
Yeah that was just a c/p fail when I had to add it here, sorry!Distraint
I'm pretty sure Windows also won't allow you to redirect standard input/output/error across the admin/non-admin security boundary. You'll have to find a different way to get output from the program running as admin - Reference: stackoverflow.com/a/8690661Backbend
Well, that would be one reason to want to use a manifest like this of course.Wongawonga
I
2

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

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.

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

Idette answered 6/11, 2010 at 6:20 Comment(1)
I'm pretty sure Windows also won't allow you to redirect standard input/output/error across the admin/non-admin security boundary. You'll have to find a different way to get output from the program running as admin - Reference: stackoverflow.com/a/8690661Backbend

© 2022 - 2024 — McMap. All rights reserved.