Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

up vote 6 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
    
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 '09 at 15:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.