Use Windows PowerShell to Make Multiple Executables Always Run as Administrator (Compatability Mode)
![[attachment-zFCOoa]](/files/2024/03/08/windows_runasadmin_compatability_thumb_300.jpg)
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]](/files/2024/03/08/windows_runasadmin_registry_thumb_300.jpg)
We can perform this action in bulk with a very terse little
$files = Get-ChildItem ./ -Include *.exe; foreach ($f in $files)
{
$filename = $f.FullName
Comments
There are no comments for this item.