There is no way to make an application to run as admin by default
See original GitHub issueI’m trying to get an always-admin executable with .net Core. I’m new to this, so please bear with me.
The “published” executable doesn’t contain the application manifest I specified in the csproj file, instead that manifest is embedded in the DLL. This means that there is no way to always request elevation via UAC prompt.
This has been checked with the following commands executed in a WSL console:
Command: strings ConsoleApp1.exe | grep requestedExecutionLevel
Output: <requestedExecutionLevel level='asInvoker' uiAccess='false' />
Command: strings ConsoleApp1.dll | grep requestedExecutionLevel
Output: <requestedExecutionLevel level='requireAdministrator' uiAccess='false' />
Reproduced with:
Build command:
dotnet publish -r win10-x64
C# code:
static bool isAdmin()
{
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
.csproj contents:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationManifest>app1.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Security.Principal.Windows" Version="4.4.0" />
</ItemGroup>
</Project>
Environment data:
dotnet --info
output:
Click to expand
Herramientas de la línea de comandos .NET (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.0\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
+1 this is a pretty important feature.
This issue was moved to https://github.com/dotnet/runtime/issues/3317