What is the command to remove an in use file in cmd.exe?

In general, there is no command for that, you have to close the program using the file, or at least force it to close its link to it.

You can find more details on this question : How do I delete a 'locked' file?

Be careful though about using Unlocker, closing handles is not a safe operation, it can lead to loss of data, or invalid state in a program (more details here). You have to be sure that you know the program using the file, and that you can safely close it, or force it to release the file.


If the file is a module/library, you can use TASKLIST /M to find out which processes are using it:

TASKLIST /M someLibrary.dll

You'll see output like this:

Image Name                     PID Modules
========================= ======== ============================================
someApp.exe                   1234 someLibrary.dll

Then you can use TASKKILL to kill the offending process:

TASKKILL /F /PID 1234

If the process is killed successfully, you'll see this output:

SUCCESS: The process with PID 1234 has been terminated.

If the file is not a library, there's no easy built-in command to figure out who is using it. In that case, I would recommend Process Explorer from Sysinternals. From there, you can search for open handles and find out which programs are using which files.

Tags:

Command Line