Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Posted

1 solution

Go to the Propertis page of your project in Visual Studio, click on Linker -> Manifest File in the tree view. Then in the right hand pane select the privilege you require in the UAC Execution Level selector. In all cases this will raise the prompt in Windows unless UAC is turned off.
 
Share this answer
 
Comments
Member 8032827 12-Apr-13 6:36am    
I am using Visual Studio 2005 and it does not have the option of "UAC Execution Level".
Can I modify the default manifest file?
Richard MacCutchan 12-Apr-13 7:01am    
I think so, but it's a while since I did it (or used VS 2005). You need to have an entry like: <requestedexecutionlevel level="requireAdministrator" uiaccess="false">. Are you sure there is nothing in the properties that allows you to change it?
Member 8032827 15-Apr-13 0:49am    
Hi thanks for the response.
I have checked it on forums as well there is no properties option in VS 2005 for doing so.
Richard MacCutchan 15-Apr-13 2:55am    
Did you see this MSDN article?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900