kraigh
Posts: 4
Joined: Fri Mar 28, 2008 2:08 am

Set Execution Level on application for Vista

I see that I can change the execution level for the EXE bootstrapper, but is there a way to set it for my application, or can the the "Run as Administrator" property on a shortcut be set? I want my application to run as Administrator.
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Set Execution Level on application for Vista

kraigh,

for this you need to set the respective setting in the manifest of the .exe file.
The manifest can be considered metadata that is integrated into the .exe file.
The manifest can be changed with mt.exe - the manifest tool.

Code: Select all

mt.exe -manifest themanifestfile.manifest -outputresource:myexecutable.exe
This is the manifest that I used for setting "RequireAdmin" in the past (store it as UTF-8 explicitly, to be on the safe side):

Code: Select all

<?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="TeamDrive"
		type="win32">
	</assemblyIdentity>
	<description>TeamDrive</description>
	<dependency>
		<dependentAssembly>
			<assemblyIdentity
				type="win32"
				name="Microsoft.Windows.Common-Controls"
				version="6.0.0.0"
				processorArchitecture="X86"
				publicKeyToken="6595b64144ccf1df"
				language="*">
			</assemblyIdentity>
		</dependentAssembly>
	</dependency>

	<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
		<security>
			<requestedPrivileges>
			<requestedExecutionLevel
				level="RequireAdministrator"
				uiAccess="false"/>
			</requestedPrivileges>
		</security>
	</trustInfo>

</assembly>
The .exe might already have a manifest or relevant information in its manifest, so don't just overwrite that with the above manifest, instead use manifest tool to extract and look at the existing manifest, too:

Code: Select all

mt.exe -inputresource:myexecutable.exe -out:myexecutable.exe.manifest
It might be possible to use manifests that are not embedded into the executable but instead lie next to it, but I have no experience with that.


With best regards

Clemens Anhuth
kraigh
Posts: 4
Joined: Fri Mar 28, 2008 2:08 am

Re: Set Execution Level on application for Vista

Cool. Thanks. That's what I needed - was just hoping for something simpler :)

Return to “Common Problems”