我怎样才能在一个特定的位置打开一个cmd窗口,而不必一直导航到我想要的目录?


当前回答

这将向上下文菜单添加条目,以启动一个自动导航到您所单击目录的命令窗口。

用法:

Right-click a folder icon (or the empty background area inside an already open folder)
and click either "Open in Terminal" or "Open in Terminal (Admin)".

You can also right click files to execute them with a command window.
When the file is done running you are left with a command window that is navigated to the files directory.

Open_in_Terminal.reg

Windows Registry Editor Version 5.00

; Admin versions.

; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%1\"'\""

; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""

; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""

; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \\\"%W \\\" && \\\"%1\\\"'\""

; Non-Admin versions.

; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%1\""

; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%V\""

; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%V\""

; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow\command]
@="cmd.exe /k pushd \"%W\" && \"%1\""

这需要很多努力,所以如果你觉得慷慨,然后随时发送一个贝宝捐赠,以帮助我克服调试和测试的创伤后应激障碍:)

一个卸载程序,如果你需要:

Open_in_Terminal_Remover.reg

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]

其他回答

你还可以这样做:

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="command prompt here"
[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="cmd.exe /c start \"%1\" cmd.exe /k cd /d %1"
[HKEY_CLASSES_ROOT\Drive\shell\cmd]
@="command prompt here"
[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="cmd.exe /c start \"%1\" cmd.exe /k cd /d %1"

更新:Win10你需要ShowBasedOnVelocityId -见上面的答案。

用一个只有一行的批量文件:

START "Desire_Path" //不带引号用cmd输入你想要开始的位置

示例(打开文本编辑器,将代码放在那里,并以.bat扩展名保存文件):

START cd C:\Users

然后双击它

****注意:如果你想让资源管理器完成任务,不要放CD命令。

*做相反的事情:

为了让你在使用cmd时使用explorer.exe应用程序打开一个特定的目录,你可以使用START命令和你想显示的文件夹的绝对路由。

该方法使用cmd.exe和发送快捷方式,使cmd.exe可以直接打开目录。这种替代方法是在没有打开命令窗口在这里右键单击菜单。

打开“文件资源管理器”,在位置栏中输入shell:sendto,导航到“发送到文件夹”。 复制命令提示符快捷方式或创建一个新的快捷方式.lnk文件。 编辑快捷方式的属性,并将目标编辑为%windir%\system32\cmd.exe /k cd /d,然后按“OK”保存更改。 右键单击一个文件夹并展开“发送到菜单”以使用cmd快捷方式。

这个快捷方式应该打开一个cmd窗口,由右键单击选择的目录。

该方法至少在windows 7和10下有效。将快捷方式命名为命令提示符(cd)以指定快捷方式的任务。

可能的错误消息:

显示'目录名无效。'如果不是folder is 选中。 系统无法找到指定的驱动器。如果文件夹是 不存在。 文件名、目录名或卷标签语法不正确。如果选择了多个文件。

简单介绍一下快捷方式:在Send to下使用时,目录会作为参数自动添加到快捷方式的末尾,因此快捷方式不需要输入目录。

如果你从任务栏启动cmd,这是你需要做的:

在命令提示符上右键单击——>——>属性

然后在属性窗口中更改Start in的值:

此解决方案不适用于以管理员身份打开命令提示符

这个答案适用于windows 10。

在文件夹中创建一个命令提示符快捷方式,然后右键单击该快捷方式

and