Run your C# Application as Administrator in Windows 7/ Vista

The following manifest XML tells the .NET Framework to run the Assembly that you specify as Administrator within Windows Vista:

<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version=""
  type="win32" />
  <description>This is description of created application</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" />

Now, there are two ways to make your program use this Manifest:

1. Rename it to (YourEXEName).manifest. The .NET Framework when executing the file will see the Manifest and handle its contents.
2. Embed the .manifest file into you EXE. This can be done by executing the following on visual studio command line (Command Prompt):
mt -manifest YourProgram.exe.manifest -outputresource:YourProgram.exe
If your assembly is strong named, you will be unable to embed the manifest into it as it would invalidate the strong naming.
Now your own C# application will prompt to run as Administrator in Windows Vista or Window 7.

in Visual studio 2010 you can also add manifest by adding by right click on project and select add new item and select manifest file from the list and modify this file as above xml.

Posted in Uncategorized. 1 Comment »

One Response to “Run your C# Application as Administrator in Windows 7/ Vista”

  1. Antonio Garcia Says:

    ClickOnce does not support the request execution level ‘requireAdministrator’

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: