Using .Net MAUI in Visual studio preview i am unable to run things that require administrator privileges for a Windows application.
I have tried the following:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<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>
</assembly>
<ApplicationManifest>app.manifest</ApplicationManifest>
I have a very similar WPF application, that also runs in .net 6 where admin privileges works if you run Visual studio as an administrator.
You're on the right track but you need another ingredient. Open the package.appxmanifest
file with a text editor and make sure that the Capabilities
node looks like this
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="allowElevation" />
</Capabilities>
I've added the allowElevation
one.
Then in your app.manifest
add this part right under the assembly
node
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
You can tweak the level as needed. It seems that if you set the uiAccess
to true that is not supported. Also, elevation is only available from WinAppSdk 1.1+ and on:
See: https://learn.microsoft.com/windows/apps/windows-app-sdk/stable-channel#elevation