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


当前回答

我刚刚看到这个问题,无法帮助发布我的自动热键脚本在Windows XP上的cmd。您可以在脚本中找到热键。好的事情是,当你当前的窗口是资源管理器时,cmd将在地址栏显示的路径中打开。

我把这个脚本保存在存放所有绿色工具(包括自动热键)的文件夹中。对于一台新机器,我只需复制文件夹,双击脚本将.ahk与AutoHotkey关联起来,并在启动文件夹中创建一个快捷方式。它比安装PowerToys还要快。

; Get working folder
GetWorkingFolder() {
    if WinActive("ahk_class ExploreWClass") or WinActive("ahk_class CabinetWClass") {
        ControlGetText, path, Edit1
        return %path%
    } else if WinActive("FreeCommander") {
        Send, {CTRLDOWN}{ALTDOWN}{INS}{ALTUP}{CTRLUP}
        Sleep, 100
        return clipboard
    } else {
        return "C:\"
    }
}

#IfWinActive,

#c::
    path := GetWorkingFolder()
    Run, %ComSpec%, %path%
    return

; PowerShell
#+C::
    path := GetWorkingFolder()
    Run, %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe, %path%
    return

#^c::
    Run, %ComSpec%, %temp%
    return

#!c::
    path := GetWorkingFolder()
    Run, %comspec% /k "%VS90COMNTOOLS%vsvars32.bat", %path%
    return

; irb
#!b::
    path := GetWorkingFolder()
    Run, c:\cygwin\bin\ruby /usr/bin/irb, %path%
    return

; Bash
#b::
    path := GetWorkingFolder()
    Run, bash --login, %path%
    return

; Paste in console
+INS::
    if WinActive("ahk_class ConsoleWindowClass") {
        WinGetPos, x, y, w, h, A
        MouseGetPos, mx, my
        ;MsgBox x=%x% y=%y% w=%w% h=%h% mx=%mx% my=%my%
        if (mx < 10)
            mx = 10
        else if (mx > w - 30)
            mx := w - 30

        if (my < 40)
            my = 40
        else if (my > h)
            my := h - 10

        MouseClick, right, mx, my
    }
    return

对于任何感兴趣的人,你可以在github上的rwin上找到这个脚本

其他回答

如果您使用的是Windows Vista或更高版本,请按住Shift键右键单击资源管理器中的文件夹图标,然后单击“在此打开命令窗口”或“在此打开PowerShell窗口”上下文菜单选项。

如果你已经在你想要的文件夹中,你可以执行以下操作之一:

[only Win8+] Click the Explorer Ribbon's File button, then click on "Open command window here" or "Open PowerShell window here". Shift-right-click on the background of the Explorer window, then click on "Open command window here" or "Open PowerShell window here". (recommended by Kate in the comments) [only Vista or Win7] Hold down Shift when opening the Explorer File menu, then click on "Open command window here". If you can't see the menu bar, open the File menu by pressing Alt-Shift-F - Alt-F to open the File menu, plus Shift.

对于Windows XP,使用dF提到的PowerToy来获得相同的功能。

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

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

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

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

如果你使用全面指挥官,在底部有一个字段。它显示您当前所在的活动目录,并将在该目录中运行输入的命令。

Windows 10文件资源管理器现在有一个“快速访问工具栏”。

只需按“Alt+F”打开文件菜单,导航到“打开Windows PowerShell”菜单,右键单击并选择“添加到快速访问工具栏”:

现在你会看到一个你可以点击的小图标,它会在你所在的目录下打开PowerShell:

更新:这是内置在Windows现在。请看这个答案。

XP的动力玩具是一个不错的选择,但我想我要发布另一个,以防你想“滚你自己的”。创建一个文本文件,命名为任何。Reg,粘贴下面的代码,保存它,然后双击它将其添加到注册表中(或者只要手动将信息添加到注册表中,如果您了解这个. Reg文件中发生了什么)。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...]
@="Command Prompt Here..."

[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...\command]
@="cmd.exe \"%1\""

更新:在windows更新后,Win10删除了cmd-here功能。要重新激活它,你必须使用:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="@shell32.dll,-8506"
"Extended"=""
"NoWorkingDirectory"=""
"ShowBasedOnVelocityId"=dword:00639bc8

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

ShowBasedOnVelocityId为必选项