How to run application with Admin privileges using Manifest file in Visual Studio 2005?

Lipika picture Lipika · Apr 12, 2013 · Viewed 26.7k times · Source

I need to create an application which needs to create files/folders in "C:\Program Files","Users[username]" and Sys32. Also the application needs to make some registry entry.

This application needs to work on Vista and higher. Also, on Windows Server 2003 and higher.

The above Operating Systems have the concept of User Account Control (UAC), where to access Program Files and writing in registry requires admin privileges.

I looked into many forums and found that using Microsoft SDK we can check whether the current user have admin privileges or not . But the function "CheckTokenMembership" fails for Vista and higher version of OS.

I also found a solution where manifest file can be used to tell OS in advance that the current application requires admin privileges. This is done using "requestedExecutionLevel" tag.

I am using Visual Studio 2005 to create the application. When we create an application in Visual Studio a default manifest file is created. Can I change this manifest file to include "requestedExecutionLevel" tag, so that my application always runs with admin privileges?

Is there any other method through which my application runs with admin privileges without asking user (admin or standard) to run my application as "run as admin"??

Thanks!

Answer

snowcrash09 picture snowcrash09 · Aug 11, 2014

You should find an option for this in project properties Linker -> Manifest File -> UAC Execution Level. Set this to requireAdminstrator.

This will cause the default generated manifest to include the requestedExecutionlevel that you need, so that your users will be prompted automatically to elevate their privileges if they are not already elevated.

screenshot of visual studio UAC options