=^.^=

Use Windows PowerShell to Make Multiple Executables Always Run as Administrator (Compatability Mode)

karma
[attachment-zFCOoa]
Application Compatibility Tab

To always run an executable under the Administrator account one will typically:

  • Right-click on the application file in File Explorer
  • Click the Properties item in the context menu
  • Navigate to the Compatibility tab
  • Check the Run this program as an administrator checkbox
  • Click the Apply button at the bottom of the Properties window

However, what is one to do when presented with a large batch of such files? Group-selecting them will reveal a Properties window of limited options, excluding the ability to mass-apply the Run this program as an administrator option to the group.

Counterintuitively, this property is not actually attached to the file itself. It is in fact set in the Windows Registry under the path HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers by making a new value for each path to an individual executable file and assigning it the String value RUNASADMIN

[attachment-NCcq3C]
The Windows Registry after running the following PowerShell snippet on the SysInternals Suite

We can perform this action in bulk with a very terse little PowerShell scriptlet which you can paste directly into your session (running as Administrator), simply chdir (cd) to the desired directory to use unmodified:

$files = Get-ChildItem ./ -Include *.exe; foreach ($f in $files) { $filename = $f.FullName reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v $filename /t REG_SZ /d "RUNASADMIN" /f }

Comments

There are no comments for this item.