0

IDE: Jetbrains Rider,C#, .NET 6.0, Windows 10

I need to edit the app.manifest because the application needs administrator rights to execute some netsh commands to change the windows firewall. Everytime i try to launch the program, it crashes though because something of my app.manifest is incorrect. Can i somehow generate an app.manifest, or copy a template or something?

In app.manifest i have <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

In my .csproj file this is what my <propertygroup> looks like:

<PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net6.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <UseWPF>true</UseWPF>
        <ApplicationManifest>app.manifest</ApplicationManifest>
    </PropertyGroup>

Thanks in advance!

Quicksoapy
  • 21
  • 4

1 Answers1

0

The default manifest that is embedded into the assembly when you build the app looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0" name="YourAppName.app"/>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

You can copy and edit it as per your requirements.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • It still does not show a prompt asking admin privileges. Perhaps something else is missing or wrong? – Quicksoapy Mar 09 '22 at 14:01
  • It should assuming you changed the `level` to `requireAdministrator` and have UAC enabled: https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator – mm8 Mar 09 '22 at 14:11
  • Odd, i've checked again and UAC is enabled. The slider is all the way up, which should mean UAC is fully enabled. – Quicksoapy Mar 16 '22 at 10:12
  • I cannot reproduce your issue. – mm8 Mar 16 '22 at 13:38