I have a Unix shell script which will kill any process that is accessing a folder:
fuser -k ..\logs\*
Is there a Windows batch script equivalent to this? I am aware of TASKKILL but I'm not sure if it will do what I need. Does anyone know if this is possible with Windows shell?
Not with built-in tools (there is nothing that can enumerate handles), but you can use the Sysinternals Handle tool to get a list of the PIDs that have open handles on a file. You can then parse the output with FOR /F
and use TASKKILL
to end the processes.
Example:
for /f "skip=4 tokens=3" %i in ('handle ..\logs\') do taskkill /pid %i
skip=4
skips the copyright information in Handle's output and tokens=3
picks out the PID from each line of output. The rest are self-explanatory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With