Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VC++ 8, CppUnit, Vista: How to do unit testing with elevated permissions?

Posted on 2008-06-26
6
Medium Priority
?
948 Views
Last Modified: 2012-08-13
unit tests fail when registering COM Dll components...

Hi experts,

My old unit tests fail when testing registration of COM Dll components on Windows Vista machine. The reason probably is more general. It may not be specific to the registering the component. I think the reason could be that the process does not get the elevated permissions. Can you share your experience with such cases? I am ready to add any details that you need to know for the answer.

I am using CppUnit for Windows from http://cppunit.sourceforge.net (I believe that it is version 1.12.0). It was integrated to VS 2005 C++ using the recommended way => the test is run automatically after building and its output is redirected to he Output window of the IDE. The IDE with C++ is started with elevated permissions.

Thanks,
   Petr
0
Comment
Question by:pepr
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21875347
The issue might be related to the User Account Control (UAC), the new security feature in Windows Vista, whereby processes do not automatically run with administrator privileges even if the current user belongs to the administrators group. The following article might be useful as it describes how to add an application manifest that will ask for elevated privileges when the application is started or when needed depending on how you configure it:

http://msdn.microsoft.com/en-us/magazine/cc163486.aspx
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 21875667
Add a manifest to your module that requests elevated permissions on startup by setting 'requestedExecutionLevel' to 'requireAdministrator', see also http://www.microsoft.com/downloads/details.aspx?FamilyID=BA73B169-A648-49AF-BC5E-A2EEBB74C16B&displaylang=en ("Windows Vista Application Development Requirements for User Account Control Compatibility")
<?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="MyModule"
     type="win32"/>
  <description>Description</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Open in new window

0
 
LVL 29

Author Comment

by:pepr
ID: 21951966
Sorry for my delay. jkr, thanks for pointing out the MS document (sorry, I have not read it yet). I am very new to using manifests. The project already generates some manifest in the directory for the configuration (i.e. Debug, Release, ...). The executable is also generated there.

For example (I use only Debug configuration for the tests), Debug/testFunction.exe exists and I can find Debug/testFunctions.exe.embed.manifest and Debug/testFunctions.exe.intermediate.manifest. I can also find Debug/testFunctions.exe.embed.manifest.res there. However, the Debug directory is generated. This means that the files are also generated.

In Project -- testFunction Properties... (Alt+F7) I can find something related to manifests -- see the pictures below.

How should I modify the project properties to information related to application security requirements there? Is the manifest linked to the .exe or must it be always placed neare the .exe?

Thanks,
   Petr
img1.png
img2.png
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 21958274
Well, create a filecalled MyModule.dll.manifest and add that as a manifest resource.
0
 
LVL 29

Author Comment

by:pepr
ID: 22013938
Still not able to get it. I have to do other things now, but I promis to try later.
0
 
LVL 29

Author Closing Comment

by:pepr
ID: 31470890
I do not know when I get to solve the problem (having other things to do now). Anyway, thanks for enlighting the problem. It seems I have new things to study ;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question