I have a console application that was developed to be called by a erp software.
They call my app inside the erp and when they do it, i always get errors related to the insufficient permission to do it.
I have checked the "run this program as an administrator" checkbox in the properties of the exe for all users but the result is the same.
I have read something about adding a manifest that will make the app prompt for the uac dialog, but thats not what i want because the app will be called from erp on the server and clients will not see the dialog on server.
Can someone explain me how to make this console app always run as administrator?
Add into your project Application Manifest File (Add -> New Item -> General -> Application Manifest File) and add the below node into the app.manifest:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx
create a batch file containing something like:
Where %USERDOMAIN% and %USERNAME% are replaced by your admin account details.
And run that instead?
First, understand that there WILL BE a UAC dialog at some point in this process. There is no way to avoid it. There are a few approaches you can take:
runas
verb is an approach here. This puts the burden on the ERP developer and they may not be able to do it.UseShellExecute
set to true, or the manifest will be ignored.If you choose the first option, the UAC prompt will be every time the ERP app launches. Not good. If you choose the second or third, the UAC prompt will be every time your console app is launched from the ERP app. Probably acceptable.
One other thing you might consider is looking far more seriously into why the console app needs admin privs. Are you writing to the root of C or to Program Files? Are you updating a registry key in HKLM? Whatever you're doing, why are you doing it that way? Unless your app installs or configures something (in which case getting a UAC prompt is good and proper) you should try to adapt it so that it writes to pre-user storage and doesn't need elevation. Then you will no longer be worrying about how to launch it elevated, in any case.