Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hello,
 
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.
Posted 21-Nov-12 23:39pm
Comments
Jochen Arndt at 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 at 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).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Albert Holguin at 25-Nov-12 1:32am
   
Pretty much it... +5
Rocky_Bas at 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 at 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.

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

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 CPallini 170


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100