Untitled

快速回答:
在 Windows 下,你可以用 openfilesSysinternals 的 handle.exe 來查詢是哪個 process 正在鎖定檔案或資料夾。這些工具都能在命令提示字元 (CMD) 中使用。


🔑 方法總覽

方法 工具/指令 使用方式 注意事項
內建工具 openfiles /query 先啟用:openfiles /local on,重開機後再執行 openfiles /query /fo table \| find /I "<檔案路徑>" 必須事先啟用,否則查不到本機檔案
Sysinternals 工具 handle.exe 安裝:winget install Microsoft.Sysinternals.Handle,再執行 handle.exe <檔案或資料夾名稱> 不需重開機,結果更完整
GUI 工具 Resource Monitor (resmon) 在「CPU → Associated Handles」搜尋檔案名稱 需手動操作 GUI,不是純 CMD
進階 GUI 工具 Process Explorer Ctrl+F 搜尋檔案名稱,顯示相關 process 可直接關閉 handle,但需謹慎

Sources:


🖥️ CMD 實際範例

  1. 啟用 openfiles 功能:

    openfiles /local on
    

    (執行後需要重開機)

  2. 查詢目前被鎖定的檔案:

    
    openfiles /query /fo table | find /I "C:\Users\Juiwen\Documents\test.txt"
    

    這會顯示 PID (Process ID) 與檔案路徑,讓你知道是哪個程式鎖住。

  3. 使用 Sysinternals Handle 工具:

    handle.exe C:\Users\Juiwen\Documents\test.txt
    

    會列出所有正在使用該檔案的 process。


⚠️ 注意事項

  • 結束 process 或關閉 handle 前要小心:可能導致程式崩潰或資料遺失。
  • 如果只是想知道「誰在用」,建議先用 openfileshandle.exe 查詢,不要直接強制關閉。
  • GUI 工具 (Resource Monitor / Process Explorer) 在定位問題時更直覺,但 CMD 工具適合自動化或遠端排查。

Also See

File5FileLast Modified
Everything極高速Windows 檔案搜尋工具Everything極高速Windows 檔案搜尋工具1:25 AM - December 07, 2025
Windows多種命令列工具搜尋檔案Windows多種命令列工具搜尋檔案8:21 PM - December 06, 2025
Windows 如何用where找檔案Windows 如何用where找檔案8:21 PM - December 06, 2025
Windows PowerShell Execution PolicyWindows PowerShell Execution Policy8:21 PM - December 06, 2025
windows batch file with path namewindows batch file with path name8:21 PM - December 06, 2025