Search code examples
c#visual-studiomanifestuac

c# Embed manifest file within .exe using mt.exe v1.0.0.0


I have a legacy console application made in visual studio .NET 2003. I am trying to embed without success a manifest file within .exe generated when building because I want to avoid UAC in windows 7 ultimate to popup when my app launches.

So my manifest file is below which is called MyTestApp.exe.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="IsUserAdmin"
     type="win32"/> 
  <description>SDPUpdater for ServiDirPlus</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

Then within Visual Studio .NET 2003, in post-build action I write following command:

"C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Common7\Tools\Bin\winnt\mt.exe" -manifest "$(ProjectDir)$(TargetFileName).manifest"

taken into account that:

$(ProjectDir) : C:\MyProjects\ConsoleApps\MyTestApp\
$(TargetFileName) : MyTestApp.exe

My manifest file MyTestApp.exe.manifest is in C:\MyProjects\ConsoleApps\MyTestApp\

But below error appears:

Performing Post-Build Event...
Microsoft (R) Side-By-Side Manifest Tool 1.0.0.0
Copyright (C) Microsoft Corporation 2000-2001.  All Rights Reserved.

Nothing to do!
Modes of operation:
   -hashupdate         Update hashes of member files
   -makecdfs           Generate CDF files to make catalogs
   -verbose            Disply piles of debugging information

Modifiers:
   -manifest <foo.man> The name of the manifest to work with

Normal usage:   mt.exe -hashupdate -makecdfs -manifest foo.man

Project error: A tool returned an error code from the build event
 
Post-Build Event failed

I think I have to indicate to mt.exe that my manifest file must be embed within MyTestApp.exe but I do not know how because mt.exe v1.0.0.0 only has 1 modifier (manifest), it does not provide any way to indicate my MyTestApp.exe file.


Solution

  • I have used mt.exe (Microsoft (R) Manifest Tool version 5.2.3790.2075) and using this line at post-build:

    "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetFileName).manifest" -outputresource:$(TargetFileName);#1
    

    now it compiles ok.

    Now, I have another problem:

    Once I launch console app, the uac popup notification continue appearing.

    My console app is wrting to a folder in C:\Program Files\ that is mine.

    But better to open another post about it. This is resolved.