Hello,
Manually, this can be achieved by right clicking on the EXE -->
"Properties" -->
"Compatibility" tab -->
"Run this program as an administrator" option.
However, in order to achieve this programmatically, we will need to make use of the following registry key:
Code: Select all
HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
Here is a PowerShell script which will do what you want:
Code: Select all
$runAsAdminReg = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
$name = "C:\Users\Catalin\Desktop\sample.exe"
$value = "RUNASADMIN"
New-ItemProperty -Path $runAsAdminReg -Name $name -Value $value -PropertyType string -Force | Out-Null
This can be added in your project as a
"PowerShellInlineScript" custom action. The custom action should be scheduled after the
"Add resources" action group, on deferred. This is due to the fact that during the
"Add resources" action group, the files are copied over to the target machine (your config file). Also, since you are bringing modification to the registries, the setup should run as administrator.
Hope this helps.
All the best,
Catalin
FOLLOW US
Get the latest news in Application Packaging