Fuzz Evans
Fuzz Evans

Reputation: 2943

How to modify compatibility settings for a file through CMD?

I have a package that gets distributed to multiple machines including a batch file that moves some files into directories. One of the files that gets moved is an executable (.exe). This exe will be ran on a schedule, once the batch file runs for the first time, and moves files accordingly, it is never used again.

If I right click the .exe file > Properties > Compatibility, there is an option under Settings to run this program as an administrator. The application only seems to work when it is ran as an administrator, so I would like to enable this setting whenever the batch file runs.

Is there a way to modify this setting within a batch or via CMD?

What I continue to find in my search, is how to run cmd as admin, or how to add a runas command to the batch so the batch itself is executed as a admin. Since the batch file is only run at setup, and never again, I need a way to set the settings for the exe itself to run as admin.

Upvotes: 5

Views: 10961

Answers (1)

KennyBOT
KennyBOT

Reputation: 447

Based on the info provided in this answer you can add the full path to the registry key Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers with the REG command like so:

Everything should be on one line but for clarity I put each argument on a separate line

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
    /v "c:\full\path\to\your\exe\file.exe"
    /t REG_SZ
    /d "RUNASADMIN"

Above command sets the compatibility flag for all users/system wide. If you want to set it only for the current user use HKCU instead of HKLM.

Do note that setting the value in HKLM subtree requires elevation.

This is tested on Win7 but should work on Vista and Win8.

Upvotes: 5

Related Questions