Search code examples
powershellregistry

Run as Administrator - Registry Setting?


PowerShell (and other programs) offer the ability to 'Run as administrator'. Is there a registry where we could alter a setting to make this the default? Thus remove the need to right click and 'Run as Administrator'?


Solution

  • The reader who initially asked the question researched this solution using PowerShell. As you can see it adds a folder called 'runas' under the \Directory\shell.

    new-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas -Force
    
    new-ItemProperty Registry::HKEY_CLASSES_ROOT\Directory\shell\runas -Name "(default)" -Value "Open Command Prompt as Admin" -Type string -Force
    
    new-ItemProperty Registry::HKEY_CLASSES_ROOT\Directory\shell\runas -Name "Icon"  -Value "C:\\Windows\\System32\\imageres.dll,-78" -Type string -Force
    
    new-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command -Force
    
    new-ItemProperty Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command -Name "(default)" -Value 'cmd.exe /k pushd %L' -type string -Force