How to Delete a Locked File on Windows

file-permissionswindowswindows 7

I am trying to delete a file generated during my eclipse (Java) build. I have been carefully reading all of the answers from here, but none work for me so far (see below).

The file is called dataentry.war. I used Handle to identify the process owning it:

> handle64 dataentry.war
Nthandle v4.1 - Handle viewer
Copyright (C) 1997-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
ccSvcHst.exe       pid: 2720   type: File          2350: C:\Users\mmalaterre\workspace\dataentry\target\dataentry.war

ccSvcHst.exe       pid: 2720   type: File          2350: C:\Users\mmalaterre\workspace\dataentry\target\dataentry.war

ccSvcHst.exe       pid: 2720   type: File          344C: C:\Users\mmalaterre\workspace\dataentry\target\dataentry.war

ccSvcHst.exe       pid: 2720   type: File          344C: C:\Users\mmalaterre\workspace\dataentry\target\dataentry.war

So now how do I delete this file ?

Using explorer (started with admin rights), I get this dumb message that I do not have admin rights:

enter image description here

I tried using the task manager:

enter image description here

but this lead to:

enter image description here

From a cmd shell with administrator right:

>del /F dataentry.war
c:\Users\mmalaterre\workspace\dataentry\target\dataentry.war
Access is denied.

For some reason I cannot get resmon to find the handle:

enter image description here

I also tried renaming the parent directory so that it is not in my way (eclipse), but again I cannot do it:

enter image description here

If I try to delete the process from a cmd (with admin rights), here is what I get:

>taskkill /PID 2720 /t /f
ERROR: The process with PID 3856 (child process of PID 2720) could not be terminated.
Reason: Access is denied.
ERROR: The process with PID 2720 (child process of PID 700) could not be terminated.
Reason: Access is denied.

Is there any way to delete a locked file on windows ?

Best Answer

Your virusscanner is locking the file and the virusscanner is pretty well protected against killing the process, to prevent a virus trying to do the same thing.

Stop the real-time virusscanner temporarily to remove the lock. If that doesn't work reboot to remove the lock.
Then delete the file.

P.S. It is generally a good idea to exclude your compile/build/debug directory from the real-time virusscanner. The actions of a compiler/linker/debugger can look suspicious to a virusscanner and excessive checks by the virusscanner can really slow down or even interfere with a compile/build/debug session.

Related Question