How to start C # service with UAC elevated privileges in Windows 2012r2?

I have a service that requires elevated administrative permissions. The service works fine on Windows XP and Windows 2008r2, but when I run the code that checks if the application is running under an elevated administrative context on Windows 2012r2, the result is always wrong.

I've already tried adding <requestedExecutionLevel level="requireAdministrator" uiAccess="true" />

to the app manifest and it works fine when I run the same code as the console app, but as a service, the app just runs without elevated permissions - it doesn't perform operations that require administrative permissions.

Also, I'm using the code in the accepted answer here to determine if I'm running with elevated privileges.


source to share

All Articles