72

Shift-rightclicking an empty spot in Explorer displays "Open with PowerShell" instead of "Open with Command Prompt" since the Creators Update (2017-04). How can I get the old behaviour back where it shows "Open with Command Prompt"?

I tried changing the setting "Show PowerShell instead of Command Prompt when rightclicking the Start Menu or pressing Windows + X" to off, but that didn't change the shift+rightclick menu.

11 Answers 11

75

Open regedit.exe, go to HKEY_CLASSES_ROOT\Directory\shell\cmd, take ownership of the key, add your user account full permissions and change the name of the DWORD from HideBasedOnVelocityId to ShowBasedOnVelocityId to enable the command prompt entry again.

Enter image description here

Or apply Andrew Richards tweak to have both shown (cmd and PowerShell, also with entry to have elevate (running as admin) version),

Enter image description here

Enter image description here

by importing his .reg file (create a new txt file, paste the content and rename the file extension to reg):

Windows Registry Editor Version 5.00

; Command Prompt

[HKEY_CLASSES_ROOT\Directory\shell\01MenuCmd]
"MUIVerb"="Command Prompts"
"Icon"="cmd.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\background\shell\01MenuCmd]
"MUIVerb"="Command Prompts"
"Icon"="cmd.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuCmd"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open]
"MUIVerb"="Command Prompt"
"Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\open\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\runas]
"MUIVerb"="Command Prompt Elevated"
"Icon"="cmd.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuCmd\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""


; PowerShell

[HKEY_CLASSES_ROOT\Directory\shell\02MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\background\shell\02MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuPowerShell"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\open]
"MUIVerb"="PowerShell"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\open\command]
@="powershell.exe -noexit -command Set-Location '%V'"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\runas]
"MUIVerb"="PowerShell Elevated"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuPowerShell\shell\runas\command]
@="powershell.exe -noexit -command Set-Location '%V'"


; Ensure OS Entries are on the Extended Menu (Shift-Right Click)

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\cmd]
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\Powershell]
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\Powershell]
"Extended"=""
12
  • 2
    The 2nd method in your answer is good. But for someone who has no idea what to do with the .reg, just copy the file text into a .txt file & rename the file <name>.reg & double click it to run. Even though there is error message, the operation is success Sep 5, 2017 at 4:41
  • 2
    How to restore from these reg keys?
    – vee
    Jan 13, 2018 at 14:41
  • 7
    This answer didn't work for me until I applied the solution to all three of these registry paths: HKEY_CLASSES_ROOT\Directory\Background\shell\cmd, HKEY_CLASSES_ROOT\Directory\shell\cmd, and HKEY_CLASSES_ROOT\Drive\shell\cmd as directed here
    – Terrance
    Sep 5, 2018 at 13:47
  • 1
    That .reg file works like a charm.
    – MC Emperor
    Sep 14, 2018 at 22:03
  • 1
    @sdaau the blog is back online after MSFT restored all deleted blogs Apr 24, 2019 at 13:35
36

As a quick alternative to the other answers, you can type cmd on the address bar of Explorer to open a command prompt cd'd to the current directory. (If you are more of a keyboard person, you can use the Ctrl + L shortcut to focus the address bar and then type cmd.)

This works for powershell too.

Edit (2021-08-02): As @pj.dewitte pointed out, you may need to use the .exe extension (i.e. cmd.exe, powershell.exe).

4
  • 1
    For me "cmd.exe" was needed instead of only "cmd". "powershell" works too. Great alternative for the proposed registry edits!
    – pj.dewitte
    Aug 2, 2021 at 11:40
  • You're right. I guess it has something to do with the more recent versions of Windows. Thanks! Added to the answer.
    – Raphael
    Aug 2, 2021 at 12:39
  • I have Windows 10 21H2 and just cmd works. Great tip! Dec 1, 2022 at 9:50
  • Other than Ctrl + L there is also Super + F4 which does nearly same, first one highlights the current content so when you start typing it replaces everything, and former does not highlight everything. Also Super + F4 is very easy to mistake with alt f4. Jan 4 at 4:54
3

This is extremely easy to accomplish

  • In the Taskbar and Start Menu Properties window, go to the Navigation tab and uncheck the Replace Command Prompt with Windows PowerShell option.
  • Click Apply for the change to take effect.

enter image description here

Sources:

enter image description here

Additional Source:

0
3

To summarize all research and improving Andrew Richards registry tweak, I got rid off annoying sub-menus by utilizing single runas verb for legacy command prompt and implementing elevated entry for PowerShell using Start-Process from non-elevated instance called by cmd.exe:

[HKEY_CLASSES_ROOT\Directory\Background\shell\ps_uac_usr\command]
@="cmd /C powershell \"start powershell -a '-noexit -command Set-Location ''%V''' -v RunAs\""
  • v flag specifies Verb set to RunAs triggers elevation via UAC prompt;
  • a stands for ArgumentList that passes noexit option that prevents new PS window from closing upon start and Set-Location option is self-explanatory;
  • %Vpasses initial path for new command prompt (when file(s)/folder(s) is selected it will pass the location of item that was right-clicked on, if nothing is selected it is equal to working directory);
  • note, \ escaping double-quotes dictated by reg file syntax as line should be seen as @="<command>", where <command> is what actually ends up in key value data;
  • and the most critical part is proper use of ' necessary to specify that first instance of PowerShell should not parse quoted contents at all and pass arguments literally while preserving set of ' for final PowerShell to be able to ignore any rogue & (%V variable is expanded by explorer.exe prior to any execution, so we don't have to worry about it).

Nothing new, but it makes sense since this implementation preserves backwards compatibility. Legacy cmd will start even if PowerShell executable does not exist.
Combination of runas registry key placed directly inside shell key is what grants permissions. And since there may be only one such key in any unique shell key, hence the limitation that forced Andrew to not only use use sub-menus, but make them separate for CMD/PS instead of single sub-menu.
By using single root runas key for elevated cmd.exe explicitly and spawning other entries with PowerShell, it is possible to avoid annoying sub-menus.

So my custom .reg file looks like this:

Windows Registry Editor Version 5.00

; CMD

[HKEY_CLASSES_ROOT\Directory\Background\shell\q_cmd_usr]
@="@shell32.dll,-8506"
"Extended"=""
"Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\q_cmd_usr\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\shell\q_cmd_usr]
@="@shell32.dll,-8506"
"Extended"=""
"Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Directory\shell\q_cmd_usr\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Drive\shell\q_cmd_usr]
@="@shell32.dll,-8506"
"Extended"=""
"Icon"="cmd.exe"

[HKEY_CLASSES_ROOT\Drive\shell\q_cmd_usr\command]
@="cmd.exe /s /k pushd \"%V\""

; CMD (Elevated)

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="@shell32.dll,-8506"
;"Extended"=""
"Icon"="cmd.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="@shell32.dll,-8506"
"Extended"=""
"Icon"="cmd.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Drive\shell\runas]
@="@shell32.dll,-8506"
"Extended"=""
"Icon"="cmd.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

; PS (Elevated)

[HKEY_CLASSES_ROOT\Directory\Background\shell\ps_uac_usr]
@="@shell32.dll,-8508"
"Extended"=""
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\ps_uac_usr\command]
@="cmd /C powershell \"start powershell -a '-noexit -command Set-Location ''%V''' -v RunAs\""

[HKEY_CLASSES_ROOT\Directory\shell\ps_uac_usr]
@="@shell32.dll,-8508"
"Extended"=""
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\ps_uac_usr\command]
@="cmd /C powershell \"start powershell -a '-noexit -command Set-Location ''%V''' -v RunAs\""

[HKEY_CLASSES_ROOT\Drive\shell\ps_uac_usr]
@="@shell32.dll,-8508"
"Extended"=""
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\ps_uac_usr\command]
@="cmd /C powershell \"start powershell -a '-noexit -command Set-Location ''%V''' -v RunAs\""

If possible to avoid modifications to existing entries behavior, it is much less messy to instead of taking ownership of system entries in registry, simply create own. This should explain why I reused default entry which is missing icon and why the only difference of elevated prompt entries is a tiny shield icon. Instead of hardwiring text captions to specific language, lines like @="@shell32.dll,-8506" allow entries to stay localized.

Using ; to comment/uncomment "Extended"="" line allow to unhide/hide respectively this entry form default right-click menu. Hidden one is still accessed by Shift + Right Click. In my registry file, entry for elevated cmd is show by default, rest is hidden behind Shift+RMB.

Directory\shell path corresponds to right click on any folder,
Drive\shell to system drives,
Directory\Background\shell to background area of working directory in Explorer window.

By my observation, entries in right-click context menu are sorted in alphanumeric order, the same as they are read from registry. This should explain names for keys in my reg file, other than that they better be pretty unique to not collide with anything possible.

3
  • Your optimized .reg is neat, thanks. But the elevated Powershell window can't change to working folder if the folder has single quote character in its name, e.g. "Oma's Nest". It would just stay at the default "C:\Windows\system32" folder. (Tested on LTSC 2019).
    – nmhung1985
    Nov 17, 2021 at 11:04
  • 1
    nmhung1985, yes, you are right, it is a limitation. Single-quote ' has to be escaped with another one in front of it in PowerShell, so Oma''s Nest from your example. Interestingly enough, original .reg file version from Andrew Richards fails at this either (since command syntax is the same, only context is different), but it opens PS window to print out an error that happens to open in the current directory, which is more due to default behavior than his command itself. Hacky...
    – Leeroy
    Nov 18, 2021 at 0:04
  • Also note that any folder name that contains a [ will cause an error. That will be a relatively common issue. And there's a rare edge case issue where any folder name that includes a string that matches an environment variable, such as %OS%, will also fail.
    – LesFerch
    Dec 21, 2023 at 16:26
2

To hit all of the locations where Windows has changed this, you can use the following registry file after taking ownership of each key in question.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8
"HideBasedOnVelocityId"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8
"ShowBasedOnVelocityId"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8
"HideBasedOnVelocityId"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8
"ShowBasedOnVelocityId"=-

[HKEY_CLASSES_ROOT\Drive\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8
"HideBasedOnVelocityId"=-

[HKEY_CLASSES_ROOT\Drive\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8
"ShowBasedOnVelocityId"=-

I would just take ownership of the [HKCR\Directory] and [HKCR\Drive] keys recursively and force permission inheritance.

Registry Permissions and Ownership setting

1

Here’s how to replace PowerShell with CMD:

  1. Open Registry Editor, simply by searching “regedit” on Cortana/Search or via Run (Win + R)
  2. On the address bar in the Registry Editor, paste “Computer\HKEY_CLASSES_ROOT\Directory\Background\shell” and hit enter
  3. From the sidebar, find “cmd” and right-click, then select Permissions
  4. From the permissions dialog, hit Advanced
  5. Hit the Change button next to the Owner field on the top of the Advanced dialog
  6. In the input field, enter your username — this can also be the email address for your Microsoft Account. Hit enter after typing in your username/email
  7. Back in the Permissions window, select Administrators from the top section and allow Full Control by checking the Allow check box on the dialog, then apply the changes and close the window
  8. Now, delete the DWORDHideBasedOnVelocityId” for CMD from the Registry Editor
  9. You may need to restart the File Explorer from the task manager to see the changes in action.

The above method will show CMD on the context menu when your Shift + Right Click in the File Explorer. But if you want to get rid of PowerShell, you can do so by following the steps below:

  1. Follow steps 1-7 from above — but change the permissions for “PowerShell” instead of the CMD.
  2. Once you apply the new permissions for PowerShell, delete the DWORD “ShowBasedOnVelocityId” for PowerShell
  3. After that, create a new DWORD and call it “*HideBasedOnVelocityId*
  4. Double click the newly created DWORD and change the hexadecimal value to “639bc8
  5. Once again, You may need to restart the File Explorer from the task manager to see the changes in action.
0
1

The following instructions will restore the Open command window here context menu item, keeping the existing Open Powershell window here context menu item. Tested under Windows 10 1909.

  1. Press the Window key + R

  2. Type regedit. Click OK button

  3. To the Do you want to allow this app to make changes to your device? question, click Yes

  4. In regedit, navigate to Computer\HKEY_CLASSES_ROOT\Drive\shell\cmd by copying and pasting the registry path into the address bar at the top

  5. Right-click on cmd key in the left pane > Permissions... > Advanced button

  6. In the resulting window, click the Change hyperlink, next to Owner: at the top. By default the owner is Trusted installer

  7. In the resulting window, enter your username and click Check Names button. Click the OK button once it has recognised your username

  8. Back on the previous screen, working from top to bottom:

    • Tick Replace owner on subcontainers and objects
    • Click the Enable Inheritance button
    • Tick Replace all child object permission entries with inheritable permissions from this object
    • Click OK
    • Click Yes to the Do you wish to continue? question
    • Click OK again
  9. Back in regedit, in the central pane, right-click HideBasedOnVelocityId and from the context menu choose Rename. Rename the value to ShowBasedOnVelocityId

  10. Navigate to Computer\HKEY_CLASSES_ROOT\Directory\shell\cmd via the address bar and repeat steps 5-9

  11. Navigate to Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\cmd via the address bar and repeat steps 5-9

  12. Close regedit

Note: You may have to redo some of the changes after a Windows feature update.

1
  • The only detailed answer which flawlessly works :)
    – Basj
    Feb 12 at 15:28
1

A workaround without admin rights (e.g. without changing registry):

WINDOWS + R: shell:sendto (open Explorer in the send to directory of the current user (or go there manually with C:\Users\<user>\AppData\Roaming\Microsoft\Windows\SendTo.

Create a new .bat-file with cmd as only text (e.g. _cmd_here.bat).

You can now right-click on any file in the desired directory (with or without shift) -> send to -> _cmd_here.bat and the command line is opened in the directory of this file.

This costs you one click (actually mouseover) more to go into the send to submenu and you need at least one file in the directory, but beside that I think it is a solution for the problem.

EDIT 2023

Another workaround is:

  1. In the Windows Explorer click in the address bar (C:/Users/...) somewhere at the right side of the address so that the address is marked up in blue.
  2. Don't unmark, just type cmd and press enter. This will open the command shell in this folder.
0

This hides powershell from the Shift-Right Click context menu and makes cmd visible.

Using a simple text editor such as Notepad, save the following code to a file with the .REG extension (e.g. MyImport.reg). Then double-click the saved file and follow the prompts to import it into the Registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Directory\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Drive\shell\cmd]
"ShowBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Drive\shell\Powershell]
"HideBasedOnVelocityId"=dword:00639bc8
4
  • Without explaining what this does and how to use it, this is not an answer. Please edit your post to clarify. Dec 20, 2018 at 11:35
  • done!.......... Dec 20, 2018 at 11:44
  • 1
    Better, however see my edit for more of what I was expecting (not all users will know how to import content into the Registry). Dec 20, 2018 at 12:33
  • Does this work with a simple .reg file, without first taking ownership of these keys, like in the steps of superuser.com/a/1564678 ?
    – Basj
    Feb 12 at 15:27
0

Here's a script that will add the Open command window here to Explorer's right-click context menu. The script uses RunAsTI.bat to add & remove the relevant registry values as the TrustedInstaller account. This obviates changing the registry keys' permissions. Run it from an elevated command window. No restart of anything required to see the change.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
OPENFILES.EXE 1>NUL 2>&1
IF ERRORLEVEL 1 ECHO You need to run this script from an elevated command prompt. Exiting. & EXIT /B 1
TITLE Configure CMD/Powershell for the Explorer SHIFT+RIGHTCLICK menu
SET REGKEYS=HKCR\Drive\shell HKCR\Directory\shell HKCR\Directory\Background\shell
FOR %%I IN (%REGKEYS%) DO SET CMD_STRING=!CMD_STRING!REG ADD %%I\cmd /v ShowBasedOnVelocityId /t REG_DWORD /d 6527944 /f ^& REG DELETE %%I\cmd /v HideBasedOnVelocityId /f ^& 
CALL :RunAsTI CMD /C "!CMD_STRING:~0,-3!"

REM https://github.com/AveYo/LeanAndMean
#:RunAsTI snippet to run as TI/System, with innovative HKCU load, ownership privileges, high priority, and explorer support  
set ^ #=& set "0=%~f0"& set 1=%*& powershell -c iex(([io.file]::ReadAllText($env:0)-split'#\:RunAsTI .*')[1])& exit /b
function RunAsTI ($cmd,$arg) { $id='RunAsTI'; $key="Registry::HKU\$(((whoami /user)-split' ')[-1])\Volatile Environment"; $code=@'
 $I=[int32]; $M=$I.module.gettype("System.Runtime.Interop`Services.Mar`shal"); $P=$I.module.gettype("System.Int`Ptr"); $S=[string]
 $D=@(); $T=@(); $DM=[AppDomain]::CurrentDomain."DefineDynami`cAssembly"(1,1)."DefineDynami`cModule"(1); $Z=[uintptr]::size 
 0..5|% {$D += $DM."Defin`eType"("AveYo_$_",1179913,[ValueType])}; $D += [uintptr]; 4..6|% {$D += $D[$_]."MakeByR`efType"()}
 $F='kernel','advapi','advapi', ($S,$S,$I,$I,$I,$I,$I,$S,$D[7],$D[8]), ([uintptr],$S,$I,$I,$D[9]),([uintptr],$S,$I,$I,[byte[]],$I)
 0..2|% {$9=$D[0]."DefinePInvok`eMethod"(('CreateProcess','RegOpenKeyEx','RegSetValueEx')[$_],$F[$_]+'32',8214,1,$S,$F[$_+3],1,4)}
 $DF=($P,$I,$P),($I,$I,$I,$I,$P,$D[1]),($I,$S,$S,$S,$I,$I,$I,$I,$I,$I,$I,$I,[int16],[int16],$P,$P,$P,$P),($D[3],$P),($P,$P,$I,$I)
 1..5|% {$k=$_; $n=1; $DF[$_-1]|% {$9=$D[$k]."Defin`eField"('f' + $n++, $_, 6)}}; 0..5|% {$T += $D[$_]."Creat`eType"()}
 0..5|% {nv "A$_" ([Activator]::CreateInstance($T[$_])) -fo}; function F ($1,$2) {$T[0]."G`etMethod"($1).invoke(0,$2)}   
 $TI=(whoami /groups)-like'*1-16-16384*'; $As=0; if(!$cmd) {$cmd='control';$arg='admintools'}; if ($cmd-eq'This PC'){$cmd='file:'}
 if (!$TI) {'TrustedInstaller','lsass','winlogon'|% {if (!$As) {$9=sc.exe start $_; $As=@(get-process -name $_ -ea 0|% {$_})[0]}}
 function M ($1,$2,$3) {$M."G`etMethod"($1,[type[]]$2).invoke(0,$3)}; $H=@(); $Z,(4*$Z+16)|% {$H += M "AllocHG`lobal" $I $_}
 M "WriteInt`Ptr" ($P,$P) ($H[0],$As.Handle); $A1.f1=131072; $A1.f2=$Z; $A1.f3=$H[0]; $A2.f1=1; $A2.f2=1; $A2.f3=1; $A2.f4=1
 $A2.f6=$A1; $A3.f1=10*$Z+32; $A4.f1=$A3; $A4.f2=$H[1]; M "StructureTo`Ptr" ($D[2],$P,[boolean]) (($A2 -as $D[2]),$A4.f2,$false)
 $Run=@($null, "powershell -win 1 -nop -c iex `$env:R; # $id", 0, 0, 0, 0x0E080600, 0, $null, ($A4 -as $T[4]), ($A5 -as $T[5]))
 F 'CreateProcess' $Run; return}; $env:R=''; rp $key $id -force; $priv=[diagnostics.process]."GetM`ember"('SetPrivilege',42)[0]   
 'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege' |% {$priv.Invoke($null, @("$_",2))}
 $HKU=[uintptr][uint32]2147483651; $NT='S-1-5-18'; $reg=($HKU,$NT,8,2,($HKU -as $D[9])); F 'RegOpenKeyEx' $reg; $LNK=$reg[4]
 function L ($1,$2,$3) {sp 'HKLM:\Software\Classes\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}' 'RunAs' $3 -force -ea 0
  $b=[Text.Encoding]::Unicode.GetBytes("\Registry\User\$1"); F 'RegSetValueEx' @($2,'SymbolicLinkValue',0,6,[byte[]]$b,$b.Length)}
 function Q {[int](gwmi win32_process -filter 'name="explorer.exe"'|?{$_.getownersid().sid-eq$NT}|select -last 1).ProcessId}
 $11bug=($((gwmi Win32_OperatingSystem).BuildNumber)-eq'22000')-AND(($cmd-eq'file:')-OR(test-path -lit $cmd -PathType Container))
 if ($11bug) {'System.Windows.Forms','Microsoft.VisualBasic' |% {[Reflection.Assembly]::LoadWithPartialName("'$_")}}
 if ($11bug) {$path=$path='^(l)'+$($cmd -replace '([\+\^\%\~\(\)\[\]])','{$1}')+'{ENTER}'; $cmd='control.exe'; $arg='admintools'}
 L ($key-split'\\')[1] $LNK ''; $R=[diagnostics.process]::start($cmd,$arg); if ($R) {$R.PriorityClass='High'; $R.WaitForExit()}
 if ($11bug) {$w=0; do {if($w-gt40){break}; sleep -mi 250;$w++} until (Q); [Microsoft.VisualBasic.Interaction]::AppActivate($(Q))}
 if ($11bug) {[Windows.Forms.SendKeys]::SendWait($path)}; do {sleep 7} while(Q); L '.Default' $LNK 'Interactive User'
'@; $V='';'cmd','arg','id','key'|%{$V+="`n`$$_='$($(gv $_ -val)-replace"'","''")';"}; sp $key $id $($V,$code) -type 7 -force -ea 0
 start powershell -args "-win 1 -nop -c `n$V `$env:R=(gi `$key -ea 0).getvalue(`$id)-join''; iex `$env:R" -verb runas
}; $A=$env:1-split'"([^"]+)"|([^ ]+)',2|%{$_.Trim(' "')}; RunAsTI $A[1] $A[2]; #:RunAsTI lean & mean snippet by AveYo, 2022.01.28

If you want to replace the Open PowerShell window here option with Open command window here, or you want to restore the default Open PowerShell window here option, having previously changed it, you can use an enhanced version of the script.

Note a few benign things that will occur when you run either version of the script:

  • You may see a The system cannot find the drive specified. message in your CMD window
  • You'll probably see a few REG errors in the child CMD window that is created after running the script
  • Once the script has completed you'll see a Control Panel\All Control Panel Items\Administrative Tools window. This can be safely closed, as it is just a side-effect of utilising the RunAsTI snippet
-4

In Windows 10 this is now included in the taskbar settings.

Windows 10 Taskbar Settings

1
  • 4
    "This only changes the Windows + x menu, not the "Open with" menu when shift + rightclicking an empty spot in Explorer." -nelson2tm Apr 10, 2018 at 21:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .