Tuesday, July 21, 2009

UAC Compatible applications - Part 1 ( Disable Virtualization )

Vista with UAC enabled is quite a nightmare for developers , especially if you are making an existing application vista compatible.

One of the first problems we face is how UAC prompts for Administrative credentials whenever it is running an application that performs action that requires administrative privileges. As a developer, one of first steps we need to do is to disable this.

All you need to get rid of UAC prompts is the manifest files.

<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.3.0.110"
processorArchitecture="X86"
name="MyApplication"
type="win32" />
<description>MyProjectDescription</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>


There is two ways you could assign a manifest file to an application.

Method 1:
You can use Mt.exe to embed the manifest right into the application. Following commands does the job for you.

Mt.exe –manifest TPWPWDbsetup.exe.manifest TPWPWDbsetup.exe

Method 2:
The second method is to keep the manifest file along the application. The manifest file should be named as "YourApplicationName.exe.manifest".
Vista would detect the manifest and use the same settings when launching your application.

Another advantage of using the manifest file is it ensures registry virtualization is turn-off. I would really recommend developers to keep the virtualization turn-off for two reasons
a) Microsoft does seems to have plan to do away with the virtualization in the future editions of OS.
b) With Virtualization turn off, your applications is bound to throw exceptions aiding you in the test phase itself. On other hand, if the virtualization was on, your registry entries are made in localized key without showing any error.

Following are some of the settings you could use in the manifest file.


Application Marking

Virtualize?

Unmarked

Yes

asInvoker

No

requireAdministrator

No

highestAvailable

No