tags:

views:

1474

answers:

3

Hi

Once my C# program is installed on a client machine, how to force my program to run as administrator on Windows 7.

Thank's in advance

+6  A: 

You can embed a manifest file in the exe, which will cause Windows Seven to always run the program as an administrator.

You can find more details here: http://msdn.microsoft.com/en-us/library/bb756929.aspx

David
+16  A: 

You'll want to modify the manifest that gets embedded in the program. Works on VS2008 + 2010: Project + Add New Item, select "Application Manifest File". Change the <requestedExecutionLevel> element to:

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

The user gets the UAC prompt when she starts the program. Use wisely, her patience can wear out quickly.

Hans Passant
+4  A: 

Adding a requestedExecutionLevel element to your manifest is only half the battle, you have to remember that UAC can be turned off, if it is, you have to perform the check the old school way and put up a error dialog if the user is not admin (Call IsInRole(WindowsBuiltInRole.Administrator) on your threads CurrentPrincipal)

Anders
Thank you for this answer.
Mikhail Orlov