How do I configure my application to run as administrator automatically?
I have created a patch file with an executable inside of it using Winrar SFX feature.
After executing the SFX file and the extraction ends up, my executable file will never run because it doesn't have admin privileges.
I am wondering HOW I can grant administrator access to that file by some programming way (like a batch file).
I know that I can right click it, go to "Properties", choose "Compatibility" tab and then tick the box "Execute as Administrator".
The problem is that the users who will download that patch doesn't know it (and my exe only runs when you right click it and choose "Open as administrator", otherway it will never open nor display the UAC popup).
I have tried some ways, like the "Elevator Runner (Elevate me)", etc, but I'm actually looking for something simpler than.
I just need to make the exe always run as administrator.
What you need to do is embed an application manifest into the EXE.
-
Save the following as a text file called App.exe.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly>
Download the Windows SDK.
-
Inside you'll find mt.exe i.e. the Manifest Tool. Invoke it as follows:
mt.exe -manifest "App.exe.manifest" -outputresource:"App.exe";#1
If there are no errors you're done. You can delete the manifest file and distribute just the EXE. Running it should make it automatically request admin access every time.
Source
When creating your archive, Request Administrative Access.