還在 Win+R 輸入 cmd 再 cd 找路徑?兩招教你像 Linux 使用者一樣,在資料夾空白處秒開終端機。
在資料夾空白處、磁碟機根目錄、桌面:按住 Shift + 滑鼠右鍵 → 選單出現 「在此處開啟 PowerShell 視窗」 (Win 10/11) 或 「在此處開啟命令視窗」 (Win 7/8)。
修改登錄,刪除 Extended 字串值:
| 目標位置 | 登錄路徑 | 適用範圍 |
|---|---|---|
| 資料夾背景 | HKEY_CLASSES_ROOT\Directory\Background\shell\cmd | 資料夾空白處右鍵 |
| 資料夾圖示上 | HKEY_CLASSES_ROOT\Directory\shell\cmd | 資料夾圖示右鍵 |
| 磁碟機圖示上 | HKEY_CLASSES_ROOT\Drive\shell\cmd | 磁碟機右鍵 |
刪除上述路徑下的 Extended 值 (或重新命名為 Extended_Off),即可直接右鍵即見選項,無需按 Shift。建議先匯出登錄備份。
OpenCmdHere.ahk,貼入以下碼 (UTF-8 編碼);; === OpenCmdHere.ahk ===
#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%
; 熱鍵:Win + C (可自行修改 #c:: 中的 c)
#c::
OpenCmdInCurrent()
return
OpenCmdInCurrent() {
; 僅在總管/檔案總管視窗生效
if !WinActive("ahk_class CabinetWClass") && !WinActive("ahk_class ExploreWClass")
return
; 取得網址列完整路徑
ControlGetText, full_path, ToolbarWindow322, A ; Win 7/8
if ErrorLevel
ControlGetText, full_path, ToolbarWindow323, A ; Win 10/11
if ErrorLevel
return
; 清理路徑字串
full_path := RegExReplace(full_path, "^地址: ", "") ; 中文版
full_path := RegExReplace(full_path, "^Address: ", "") ; 英文版
StringReplace, full_path, full_path, `r, , All
; 判斷是否為有效路徑
if InStr(full_path, "\") {
Run, cmd /K cd /D "%full_path%"
} else {
Run, cmd /K cd /D "C:\"
}
}
修改 #c:: 中的 c 為任意鍵:#t:: (Win+T)、^t:: (Ctrl+T)、!t:: (Alt+T)。#=Win, ^=Ctrl, !=Alt, +=Shift。
將腳本中 RegExReplace(full_path, "^地址: ", "") 改為 RegExReplace(full_path, "^Address: ", "")。
| 維度 | Shift+右鍵 (原生) | AutoHotkey 熱鍵 |
|---|---|---|
| 安裝需求 | 無 | 需安裝 AHK |
| 速度 | 需兩手操作、選單延遲 | 單手一鍵、極速 |
| 適用範圍 | 資料夾、磁碟、桌面 | 僅總管視窗 |
| 穩定性 | 系統級、永不失效 | 視窗類別變更可能失效 |
| 自訂彈性 | 無 | 極高 (可加參數、改終端機) |
安裝 Windows Terminal (Microsoft Store),設定為預設終端機。再用 「右鍵選單管理工具」 (如 ContextMenuManager) 將 wt -d . 加入右鍵選單,支援分頁、多 Shell (PowerShell/CMD/WSL)、主題美化,體驗遠超傳統 CMD。
適用對象:頻繁在特定資料夾執行 CLI 指令的開發者、運維、進階使用者。偶爾用用者,Shift+右鍵已足夠。