Click here to Skip to main content
15,881,810 members
Articles / Programming Languages / VC++
Tip/Trick

Using Manifest Settings for VC6 buildchain

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
15 Apr 2015CPOL3 min read 13K   10   2
Get manifest support with VC6

Introduction

This tip explains how to get manifest support using the VC6 buildchain. I will use an example of requiring administrator rights for execution.

At the end, I will explain the background and thereby why one would need to add a manifest file in this style, rather than just leave it without one.

Obsoletion

The way this article describes is still valid, but there is a much easier and lightweight way of reaching our goal. Thanks to Daniel Rozsar's comment:

Quote from Daniel Rozsar:

you can add manifest as resource and you can use the original VC6 resource compiler to build your program with manifest file. Just add this lines to the rc file and create a maifest file for your project:

/////////////////////////////////////////////////////////////////////////////
//
// 24
//
1                       24      DISCARDABLE     "myproject.manifest"

The article will not change, though, as it still describes a valid pattern. But my suggestion would be Daniel's advice.

Prerequisites

mt.exe within the Microsoft SDK, which usually comes with newer version of Visual Studio.

Using the Code

Create the manifest File

First, we create a manifest file for the project. Let's call it "MyProject.manifest". There, we can write everything we need. For our example, we'll put in the following.

XML
<?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>
</asmv1:assembly>

Note the "level=requireAdministrator" option here. This is the option for asking for administrator privileges at application startup. The other way around would be "level=asInvoker", which would start the application with user rights, only. For further details, see the MSDN.

Insert/inject our manifest File into the EXE File

We add a new post-build event to our project. In VS2010, this would be Project -> Properties -> Build Events -> Post-Build Event. The content will look like this:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mt.exe" -nologo 
-manifest "$(ProjectDir)MyProject.manifest" -outputresource:"$(TargetPath);#1"

You should check if the path to mt.exe is valid for you. This will not work by just using "mt.exe", as that path is not known by the VC6 toolchain.

Note also that you specify the filename of the manifest file and also the path to the EXE that was built.

In case you write this by hand, do not forget the colon after "-outputresource", as it will lead to a - more or less - unclear error.

That's it! Now you can enjoy a "Hello World" program that asks for administrator privileges on startup. :)

Background

I was "upgrading" the development environment from VC6 to Visual Studio 2010 on Windows 7 using daffodil, with the VC6 plattform toolkit still enabled. Back in VC6-Times, nobody bothered about execution rights. And there were no manifest files available.

Why You Would Need to Use a manifest File

It turned out, that - without manifest files - Windows 7 presumes the need of admin privileges by evaluating the name of the EXE-file or some entries within the resource-file. If they'd contain "Setup", they're doomed to the need of admin rights (also see comment here).

In my case, I was not able to debug my setup project without having admin rights. Even worse, I could not even run my tests without logging in as administrator.

The solution provided by Microsoft (the manifest settings) are not present, if you choose to use the vc6 build-chain. (There is also no information, that the settings absence is related to the vc6 build-chain). So the only way was to "inject" it manually from the command line after the creation.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Telefonica Germany
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAdd manifest as resource Pin
Daniel Rozsar21-Apr-15 6:17
professionalDaniel Rozsar21-Apr-15 6:17 
AnswerRe: Add manifest as resource Pin
D4rkTrick2-Nov-15 17:30
professionalD4rkTrick2-Nov-15 17:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.