You can programmatically set the “Run this program as an administrator” flag (the option you find in the Compatibility tab of an EXE’s properties), by setting a simple registry key. You need to create a string value (REG_SZ) under one of these keys (if you want the setting to be per user or per machine, respectively):
HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\AppCompatFlags\Layers
or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\AppCompatFlags\Layers
The name of the value needs to be the full path to your executable (if the path contains spaces, do not surround the path with quotes) and the data of the value must contain the string RUNASADMIN
.
For sample:
reg.exe Add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files\MyApp\Test.exe" /d "PUT__VALUE__HERE"
Compatibility Modes
WIN95 Windows 95
WIN98 Windows 98
WIN4SP5 Windows NT 4.0 SP5
WIN2000 Windows 2000
WINXPSP2 Windows XP SP2
WINXPSP3 Windows XP SP3
VISTARTM Vista
VISTASP1 Vista SP1
VISTASP2 Vista SP2
WIN7RTM Windows 7
WINSRV03SP1 Windows Server 2003 SP1
WINSRV08SP1 Windows Server 2008 SP1
Privilege Level
RUNASADMIN Run program as an administrator
REG ADD “HKLM\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\AppCompatFlags\Layers” /v
“C:\temp\compatmodel\iconsext.exe” /t REG_SZ /d “WINXPSP3 RUNASADMIN”
/f
References:
http://www.verboon.info/2011/03/running-an-application-as-administrator-or-in-compatibility-mode/