下载Handle.zip文件 https://docs.microsoft.com/zh-cn/sysinternals/downloads/handle
解压到任意地方
bat 批处理
@echo off
rem handle可执行文件
SET "handle=C:\Users\too\Desktop\Handle\handle.exe"
rem 要删除的文件
SET "appfile=C:\Users\too\Desktop\test"
FOR /F "tokens=3" %%a IN (‘%handle% -nobanner %appfile% ^| FINDSTR /V explorer.exe‘) DO (
@echo %%a
@taskkill /F /PID %%a
)
备注:解除占有后可以随便删除文件。
原文:https://blog.51cto.com/vtime/2421587