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 useTASKKILL
to end the processes.Example:
skip=4
skips the copyright information in Handle's output andtokens=3
picks out the PID from each line of output. The rest are self-explanatory.