I’ve just migrated a .NET app from WinXP to Win7, and have had my first battle with the User Account Control (UAC). My problem was that I was unable to start a service on my local machine.
When calling the “service.Start()” method I received:
Exception: Cannot open screen-scraper server service on computer ‘.’.
A peek inside the inner exception revealed the more helpful message “Access Denied”. While right-clicking the application and selecting “Run As Administrator” solved the problem temporarily, I wanted a smoother solution.
I wanted the UAC dialog box to appear whenever the application is run, making the whole application admin only. In most scenarios this would be a bad idea, but this was only a small admin application.
To do this, open the project in Visual Studio 2008 and click Add -> New Item -> Application Manifest File. A small Xml file will be created in the root of the project. The application manifest allows us to customize the applications security level.
Open the Xml file and change the following line:
<requestedExecutionLevel level=" asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Notice the application icon now has the UAC shield. When the application is run, the UAC dialog will popup automatically.