# Copy a file that is being used by another process

## Main Question or Discussion Point

I have a file in my computer that I would want to delete but I always get error message of insufficient access right even though I am already an administrator. The file is being used by another process I don't know. That process seems to gag on the file forever. I scan the system but no virus is recognized.

In order to delete this file, what should I do ?

## Answers and Replies

Related Computing and Technology News on Phys.org
jedishrfu
Mentor
Can you bring up your computer in some sort of safe mode? Windows has this feature.

For linux you might use Knoppix to boot and then mount the drive of interest and find the file to delete.

However, before you delete do you know what its used for? What is its name?

Have you searched online to see if others have had problems with this same file to see what they did?

Just being cautious, I remember a scam one time was to have users delete some critical windows system file and replace it with a malware version.

I am sure there are programs that can still do this without having to enter safe mode. I'd like to know how they can do that.

jedishrfu
Mentor
On windows, you cant until you find the process that has the file locked in write mode. At least I was never able to on old versions of windows.

However, I found this writeup that may help:

http://www.wikihow.com/Delete-a-Locked-File

DaveC426913
Gold Member
Might be a much better idea to simply rename it first. Then whatever is trying to use it won't be able to, but if it's a system-critical file, you can restore it

Might be a much better idea to simply rename it first. Then whatever is trying to use it won't be able to, but if it's a system-critical file, you can restore it
Can you even rename a file if its in use? (or locked, for that matter)

To the OP: perhaps you can name the file you are trying to delete.

DaveC426913
Gold Member
Can you even rename a file if its in use? (or locked, for that matter)
I am riffing off jedishr's suggestion that might allow it.

SteamKing
Staff Emeritus
Homework Helper
It's not clear what file you are trying to delete. Windows uses a lot of scratch or temporary (and some not so temporary) files while it is active, so you want to make sure you are not trying to delete one of these files. Doing so can mess you up, sometimes catastrophically.

FactChecker
FactChecker
Gold Member
Why do you want to delete it and what do you know about that file? If you are sure you know why the file is there and still want to delete it, you may be able to force a delete with a DOS command. They often work when the Windows delete fails. Be sure you know what you're doing first. Rename probably won't work if Windows thinks the file is in use, but you can copy it to a different name and then try delete the original. If everything still works, then delete the copy. If things stop working, rename the copy to the original name.

Last edited:
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!

Medicol and jim mcnamara
jim mcnamara
Mentor
Medicol
harborsparrow
Gold Member
I have a file in my computer that I would want to delete but I always get error message of insufficient access right even though I am already an administrator. The file is being used by another process I don't know. That process seems to gag on the file forever. I scan the system but no virus is recognized.

In order to delete this file, what should I do ?
I am not sure if it is a similar problem or not, but I had an undeletable file which I blogged about here: http://harborsparrow.blogspot.com/2012/09/undeletable-files-on-ntfs-file-system.html

If the file is in use by another process, my blog will not help. But if insufficient permissions are the problem, the blog I made might help.

Routaran
In the Windows command prompt try

Code:
cd <file_path>
del <file_name> /a:s