When a file is in use, the file is locked by the process that's using it. You cannot rename/delete or do anything to modify that file other than through the process that has it locked. Generally, this means you cannot delete the file till the process releases the resource or the process itself stops.
There's two ways that come to my mind to delete the file.
1) Identify the host process that has this file locked, stop the process and then delete the file.
or
2) reboot the system into safemode (or into another OS like a Linux LiveCD) and delete the file from there.
safemode delete will work if the file we want to delete is a 3rd party app/data file. If it's a system executable or DLL you're likely to run into the same problem.
So, for the first way. Identifying the host process locking a resource. I will use the example of deleting an executable while it's running.
First, you'll need to download Process Explorer from the sysinternals website. (
http://technet.microsoft.com/en-ca/sysinternals/bb896653.aspx)
Here's the example of me trying to delete the process explorer executable while it's running
Now we have to find out which process is locking this executable.
So we click find and, type in the full name of the executable including the extension and search.
As you can see, we have 2 processes that are associated with this file. Explorer.exe is listed because it's the GUI and i double clicked the file to run it. So it shows up as it's running under Explorer.exe. This is not the process that's locking the executable. Its the other one, PID (Process ID) 4804. that's what we need to stop
So we sort by PID and find 4804. Right click on the process and Kill Process. Once it's closed, we can delete the file.
Now, you have to make sure that the file you are deleting is not system critical and the process that's locking it is not system critical. Google is your friend.
Hopefully this helps you out.
Cheers!