Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet core app run as administrator

Tags:

c#

.net-core

uac

I have a dotnet console application that requires administrator privileges to run. I can't find how to do this. In a regular project I would add a app.manifest and set

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

but I can't figure how to embed this in the build.

How do I do this?

like image 542
A Jackson Avatar asked Feb 10 '17 12:02

A Jackson


People also ask

How do I force my .NET application to run as administrator?

Right click your executable, go to Properties > Compatibility and check the 'Run this program as admin' box.

How do I always run Visual Studio as administrator?

On the Windows desktop, right-click the Visual Studio shortcut, and then select Properties. Select the Advanced button, and then select the Run as administrator check box. Select OK, and then select OK again.


1 Answers

I found the simplest workaround would be to add the app.manifest file with the setting like what in net framework app

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

then on your net core project file (.csproj in C# project) add the following:

<PropertyGroup>   <ApplicationManifest>app.manifest</ApplicationManifest> </PropertyGroup> 

*Worked in Console and WPF netcore 3.0

like image 130
tsuryadi Avatar answered Sep 20 '22 20:09

tsuryadi