Solved

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

Posted on 2008-06-26
6
940 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 500 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

829 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