Saturday, 27 April 2013

Force application to run with elevated permissions. Run as Administrator (UAC)

I've been working for a bit on a application that hosts its own wcf service, too long to explain here, but the interesting point is that in order for the web service to be locally hosted, I need to run the app using elevated permissions, which is done very easily by adding a manifest file to the application.

This is the manifest file that you need:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <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>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
    </application>
  </compatibility>
</asmv1:assembly>

You can add this file from Visual Studio and just customize to the required permission level.

No comments:

Post a Comment