6

I am trying to remove an in use file using command prompt. I am not successful so far. I have used the del command but in vain.

Please Advise.

Edit: I forgot mentioning two things.

1) This particular file is not viewable from GUI (it's not hidden), its from Downloaded Program Files folder. 2) This issue is on a clients machine, who is on a webex with me. So I cannot install Unlocker.

7 Answers 7

9

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.

3

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.

1

You cannot delete a file from cmd that is in use. Try re-booting and deleting right after the boot, when some services aren't running. Otherwise, look for the process that is using the file and kill it and then the file, or find online software to delete a file that is in use.

1

The graphical-based utility unlocker will unlock in-use files; however, I don't think it is usable via command line.

0

There is no built in file unlocker however the unlocker gui utility mentioned in another suggestion can be called from the command line once installed.

1
  • One further thing, if the file is being used from a remote machine (i.e. over a network share) you can close it by doing net file /close with the number of the file. Just do net file /? for better instructions
    – Col
    Aug 27, 2009 at 15:04
0

If application can't be deleted because it is in use by your system, You could try locating file (if you know the location of the file, if not find it via Task manager/processes bar) and "cd" via cmd to its folder. Then try "TASKKILL /f /pid "appname" & del /f "appname"", this will kill the running process and try to immidiately delete the executable. If it doesn't work, try a couple of times so it doesn't have time to restart the process and can be permanently removed in that time frame.

0

You can use handle.exe by SysInternals:

handle.exe /accepteula -p PROCESS_PID -c HANDLE_NUMBER -y

Run handle.exe -? to learn more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .