Anil Sharma

just for code

User Account Control – Run Application with Admin privileges in Vista/Windows 7

UAC – User Account Control :

Some time we need run application under admin privileges then we need to update UAC with application manifest setting.

By default, Windows Vista® and Windows Server 2008 will run every application as a standard user even if you log on as a member of the administrator’s group. Conversely, when users attempt to launch an application that has been marked as requiring administrator permissions, the system will explicitly ask them to confirm their intention to do so. Only applications running with administrator privileges can modify system and global settings and behavior. This feature of Windows Vista and Windows Server 2008 is the User Account Control (UAC).

To resolve this we need to update .manifest file of application. In manifest file it has node requestedExecutionLevel .

It has attribute “level”. For this there are three options

1-asInvoker – Runs application as logged user account.

2-requireAdministrator – Runs application as Admin privileges.

3-highestAvailable – Runs application as highest privileges under logged user account.

<!–?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=”http://www.w3.org/2001/XMLSchema-instance”&gt;
<assemblyIdentity version=”1.0.0.0″ name=”MyApplication.app”/>
<trustInfo xmlns=”urn:schemas-microsoft-com:asm.v2″>
<security>
<requestedPrivileges xmlns=”urn:schemas-microsoft-com:asm.v3″>
<!– UAC Manifest Options–>
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.

<requestedExecutionLevel  level=”asInvoker” uiAccess=”false” />
<requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” />
<requestedExecutionLevel level=”highestAvailable” uiAccess=”false” />

If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
–>
 <requestedExecutionLevel level=”asInvoker” uiAccess=”false” />
      </requestedPrivileges>
</security>
</trustInfo>
<!–asmv1:assembly>

 

If your application always requires administrator privileges, then you can change this value to “requireAdministrator”. Now, whenever your application starts it will always trigger UAC and ask the user to allow administrator access for your program.

Note that it’s worth seriously considering whether you actually need to do this, and why – especially given the intrusive experience of UAC. For instance, you shouldn’t need to write settings to Program Files, as Windows provides the user profile area and registry for just that purpose. In general UAC should hopefully force us all to think a bit more carefully about where we’re storing data, and what permissions the application *really* needs.

August 15, 2011 Posted by | Developement | , , , , , , | 1 Comment