Friday, December 02, 2022

Add Command Prompt Here to Explorer Without Mucking About With the Registry

Windows 10 computers are missing the “Open Command Prompt Here” on the shortcut menu.

You can find a registry change online that will bring it back. But that “fix” involves changing the Permissions / Ownership of that part of the registry, so I declined to try it.

Instead I came up with a solution that uses the SendTo feature to call a batch file that calls CMD with the /K switch. To use it, create a batch file in your SendTo directory called OpenCMD.cmd. Add the content below, between the “BEGIN--------” and “END--------” tokens, and save it. Then Right-Click any file, choose SendTo OpenCMD.cmd, and a command prompt will be opened in the directory in which that file resides (if the path is on a local hard drive or mapped drive).

The SendTo directory can be found under your user profile; the <UN> in the path below is your user name:

C:\Users\<UN>\AppData\Roaming\Microsoft\Windows\SendTo

You can also enter the following in the explorer address bar to navigate to SendTo: shell:SendTo

Here’s the batch file source code. Please note that most of the lines are either comments (which start with REM) or debugging statements (which start with Echo). In fact the only lines that are necessary are the ones between the labels :OpenCMD and :END.  And please don't include the “BEGIN--------” and “END--------” tokens

Begin--------

REM OpenCMD.cmd (c) 2022 Luddite Geek

REM Opens the command prompt in the directory of the given path

REM

REM 2022-11-04 LG Created.

GOTO OpenCMD

GOTO BEGIN

cmd /?

:BEGIN

@echo off

Echo %0 %1

Echo DRIVE: %~d0

Echo PATH: %~p0

Echo NAME: %~n0

Echo EXT: %~x0

Echo.

Echo Drive and Path of parameter 1: %~dp1

pause


:OpenCMD

%~d1

cd %~dp1

CMD /D /K CLS

:END

End--------

No comments: