15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

User account Control ❘ 1405<br />

An application manifest is an XML fi le similar to the application confi guration fi le. While the application<br />

confi guration fi le has the fi le extension .config, the manifest ends with .manifest. The name of the<br />

fi le mu s t b e s e t to t he n a m e of t he appl ic at ion , i nclud i ng t he . exe fi le extension followed by .manifest.<br />

Visual Studio renames <strong>and</strong> copies the app.manifest fi le just as it does an application confi guration fi le.<br />

The manifest fi le contains XML data, as shown here. The root element sembly> is a < , which contains the<br />

child element rustInfo> t < . The administrator requirement is defi ned with the level attribute of the<br />

< requestedExecutionLevel > e l e m e nt .<br />

< xml version="1.0" encoding="utf - 8" ><br />

< asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas - microsoft - com:asm.v1"<br />

xmlns:asmv1="urn:schemas - microsoft - com:asm.v1"<br />

xmlns:asmv2="urn:schemas - microsoft - com:asm.v2"<br />

xmlns:xsi="http://www.w3.org/2001/XMLSchema - instance" ><br />

< assemblyIdentity version="1.0.0.0" name="MyApplication.app"/ ><br />

< trustInfo xmlns="urn:schemas - microsoft - com:asm.v2" ><br />

< security ><br />

< requestedPrivileges xmlns="urn:schemas - microsoft - com:asm.v3" ><br />

< requestedExecutionLevel level="requireAdministrator" uiAccess="false" / ><br />

< /requestedPrivileges ><br />

< /security ><br />

< /trustInfo ><br />

< /asmv1:assembly ><br />

code snippet AdminRightsRequired/app.manifest<br />

When starting the application this way, you get an elevation prompt where the user is asked if he or she trusts<br />

the application to run with administrative privileges.<br />

With the requestedExecutionLevel setting, you can specify the values requireAdministrator ,<br />

highestAvailable , <strong>and</strong> asInvoker . The value highestAvailable means that the application gets the<br />

privileges the user has — but only after getting the consent from the user. The value requireAdministrator<br />

requires Administrator privileges. If the user is not logged on to the system as Administrator, a login dialog<br />

appears where the user can log in as Administrator for the application. The value asInvoker means that the<br />

application is running with the security token of the user.<br />

The uiAccess attribute specifi es if the application requires input to a higher - privilege - level window on the<br />

desktop. For example, an onscreen keyboard needs to drive input to other windows on the desktop, so<br />

the setting should be set to true for the application to display the onscreen keyboard. Non - UI - accessible<br />

applications should have this attribute set to false .<br />

Another way to get admin privileges to an application is to write a Windows service.<br />

Because UAC applies to interactive processes only, a Windows service can get admin<br />

privileges. You can also write an unprivileged Windows application to communicate<br />

with the privileged Windows service by using WCF or another communication<br />

technology.<br />

Windows services are covered in Chapter 25, “Windows Services.” WCF is covered in<br />

Chapter 43, “Windows Communication Foundation.”<br />

shield icon<br />

If an application or a task from an application requires administrative privileges, the user is informed by an<br />

easily recognizable shield icon. The shield icon is attached to the controls that require elevation. The user<br />

expects to see an elevation prompt when clicking on an item with a shield. Figures A - 5 <strong>and</strong> A - 6 show the<br />

shield in use. The Task Manager requires elevation to see processes from all users. Within User Accounts,<br />

adding or removing user accounts requires elevation as well as setting up parental controls.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!