Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have developed an MFC application,i have used few registry conditions in the code.As the administration will be only allowed to edit the registry through any application or code.So using my application i am not able to edit the registry.To edit the registry through my MFC application i need to right click the exe and select as Run as Administrator and then run the exe.

So is there any other way so that i can give directly in the code to run the exe as a administrator.Kindly help me to solve this.

Thank you in Advance.
Jochen Arndt 22-Nov-12 6:24am    
If your application is not something special that really requires writing to administrative registry parts, you should follow the recommended way:
An application can write to the HKCU tree (usually to store configuration and settings). General application options can be written to the HKLM tree during install and update when executed with administrative privileges. These general options can be read by the application.
Albert Holguin 25-Nov-12 1:34am    
Even though the manifest change in Solution 1 will get you what you asked... do take people's advice on how to live with UAC in a more proper way (i.e. your application shouldn't require admin privileges, only the original installer needs to make any system level changes).

In your project settings for the linker is a tab for the manifest file. There is a setting called "UAC Execution Level". Normally it is set to "asInvoker". Change it to "requireAdministrator". This will do the trick for you.
Share this answer
Albert Holguin 25-Nov-12 1:32am    
Pretty much it... +5
Rocky_Bas 27-Nov-12 21:22pm    
Actually i want this application to be runned in the startup,but if i keep the administrative rights through this way i am not able to start the exe in the start up.Is there any other way for it.
Andy Bantly 28-Nov-12 10:28am    
Yes, you should write your application as a service instead. The UI has to be separated from the work. You would then have two applications. A service and a UI component. One strategy for communicating from UI to service is by using named pipes. This is pretty straight forward. I already posted an article on creating a service. I should do an article on making UI that controls and communicates with a service.
Except if the main purpose of your application is to do administrative things, the recommanded way is to put operations that require administrator priviledge in another application and call that application from yours when you need to do that operation...

Also, it is recommanded to put a shield icon on the button that will executed that operation.

One of the purpose of the UAC is to discourage application creator to modify the system. It is a protection to limit what malware program can do without being noticed.

As much as possible, any changes that your application make to the file system or the registry should be in a portion that belong to that user. In some cases, you can also used public documents or application data...

Only at installation time, you should write to location that are common to all users.
Share this answer

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