Exercise 2: Solving the Problem

The problem identified in the last task can be solved by adding a manifest, either external or internal.

Task 1 - Adding an External Manifest

  1. Navigate to the BrokenStockUpdater\Debug folder with Windows Explorer and:

    1. Right-click an empty space.
    2. Point to New.
    3. Click Text Document.
    4. Name it BrokenManagedStockUpdate.Exe.manifest.

    Note:
    Help

    Notice that as soon as the file exists with the new name, even though it is still empty, the shield icon overlay disappears.

  2. Open the manifest file in Notepad or another text editor.
  3. Enter the following text:<?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="https://www.w3.org/2001/XMLSchema-instance">
    <assemblyIdentity version="1.0.0.0" name="StockUpdater"/>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
    </requestedPrivileges>
    </security>
    </trustInfo>
    </asmv1:assembly>

    Note:
    Help

    The critical information is the level attribute. The value asInvoker instructs the .exe file to run with the same privileges as the creator (for example, Windows Explorer), which indicates that this .exe file is not an installer, but a regular application. The other relevant level is requireAdministrator, indicating that this .exe file needs administrative privileges to operate correctly. For example, it is an actual installer and needs access to privileged locations, such as \Windows\System32 folder or HKEY_LOCAL_MACHINE\Software key.

  4. Save the file.
  5. Exit the text editor.
  6. Verify that the change works as expected by double-clicking the .exe file. This time, you should not see a UAC elevation prompt and the application should function normally.

Task 2 - Adding an Embedded Manifest

  1. For C#:
  2. Open the BrokenStockUpdater.sln solution file located in the BrokenStockUpdater folder with Visual Studio 2008.
  3. Examine the BrokenManagedStockUpdater project. This project has no manifest. To verify this:
  4. Click the Project menu
  5. Click Properties
  6. Click Application (it should be selected already). The Icon and Manifest button should be selected and the Manifest setting should say Create application without a manifest, as shown in the following screen shot:

    Note:
    Help

    The default setting in Visual Studio 2008 is to generate a manifest file.

  7. Change the Manifest setting to Embed manifest with default settings as shown:

  8. Rebuild the solution
  9. Delete the manifest file from the previous task. Make sure the shield icon disappears, and no UAC elevation prompt appears when double-clicking the application.
    Note:
    Help

    The fixed solution is in the FixedStockUpdater.sln located in the FixedStockUpdater folder.
  10. For Visual Basic:
  11. Open the BrokenStockUpdater.sln solution file located in the BrokenStockUpdater folder with
  12. Visual Studio 2008.
  13. Examine the BrokenManagedStockUpdater project. This project has no manifest by default in solution explorer.
  14. Click the Project menu
  15. Click Properties and click on “View UAC Settings”
  16. Note:
    Help

    The setting does not allow you to change the UAC level (it is set to asInvoker by default). To get other values, you can add a new item of type Application Manifest File and get the entire XML manifest to edit as text.

  17. Save and Rebuild the solution.
  18. Delete the manifest file from the previous task. Make sure the shield icon disappears, and no UAC elevation prompt appears when double-clicking the application.

    Note:
    Help

    The fixed solution is in the FixedStockUpdater.sln located in the FixedStockUpdater folder.