Shhzdmrz
Shhzdmrz

Reputation: 45

C# Application not running with administrative privilege

I am running an application that should be run as administrative right but after adding manifest file give below application still not required to run as administrator. The release and debugged executable work but while coding and debugging it does not required administrative privilege. Kindly sort this out.

Already tried these two line of code:

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

and

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

Upvotes: 0

Views: 599

Answers (1)

Hans Passant
Hans Passant

Reputation: 941465

This is a limitation imposed by using a debugger, the program you start inherits the security token of Visual Studio. Sounds like you are using an older version, starting with VS2013 you now get a reminder about this issue:

enter image description here

Which tells you what to do, "restart Visual Studio as an administrator". Right-click its shortcut and select "Run as Administrator". Acknowledge the UAC prompt you get and reload your solution. Your program now automatically runs elevated as well, note that you do not get the UAC prompt when you press F5. You need to test if your manifest is effective separately.

Another noteworthy detail about this quirk is that there are a bunch of Nuget packages around that only run correctly when VS runs elevated. And fail to work in a very hard to diagnose way, you don't get an error message when its install script fails to add a post-build event. Adding several gray hairs to the top of my head.

Upvotes: 4

Related Questions