How to add a manifest to a legacy application (which you cannot or will not recompile)

(Copied verbatim from Klaus Bjorn Jensen’s blog)

I used mt.exe from the Windows SDK at “C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe”

To add a manifest to an existing legacy exe to make it Run As Administrator (with elevated privileges) on UAC enabled systems (Vista, Win7 , Win 2008 …). Here’s how:

In the same folder as the legacy executable, create a text file called filename.exe.manifest For this example we’ll assume that the executable is called KSDiag.exe, so the manifest name will be KSDiag.exe.manifest

Put the XML data listed below into the manifest file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="False"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
  1. Run command:
mt.exe /manifest KSDiag.exe.manifest /outputresource:KSDiag.exe;1

The number on the end of the command line ;1 indicates the type of file we’re attempting to modify (1 for an EXE, 2 for a DLL)

To modify a DLL the command should be modified to:

mt.exe –manifest MyLibrary.dll.manifest -outputresource:MyLibrary.dll;2

Now KSDiag.exe has the manifest added to its resource section. On a UAC enabled OS it gets the shield icon and you get the administrator prompt when you try to run it. Of course if the file was signed to start with you’ll have to resign it.

Further information can be found on the MSDN website http://msdn.microsoft.com/en-us/library/ms235591.aspx