Copy a file that is being used by another process

  • Thread starter Medicol
  • Start date
  • #1
223
53

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

  • #2
11,524
5,075
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.
 
  • #3
223
53
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.
 
  • #4
11,524
5,075
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
 
  • #5
DaveC426913
Gold Member
18,652
2,119
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
 
  • #6
1,466
372
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.
 
  • #7
DaveC426913
Gold Member
18,652
2,119
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.
 
  • #8
SteamKing
Staff Emeritus
Science Advisor
Homework Helper
12,798
1,666
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.
 
  • Like
Likes FactChecker
  • #9
FactChecker
Science Advisor
Gold Member
5,403
1,963
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:
  • #10
447
94
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
1.jpeg


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.
2.jpeg

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.
3.jpeg


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!
 
  • Like
Likes Medicol and jim mcnamara
  • #11
jim mcnamara
Mentor
3,799
2,144
  • Like
Likes Medicol
  • #12
harborsparrow
Gold Member
533
108
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.
 
  • Like
Likes Routaran
  • #13
129
28
In the Windows command prompt try

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

Related Threads on Copy a file that is being used by another process

  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
18
Views
5K
  • Last Post
Replies
21
Views
10K
Replies
1
Views
22K
Replies
5
Views
10K
  • Last Post
2
Replies
42
Views
8K
  • Last Post
Replies
2
Views
6K
  • Last Post
Replies
4
Views
668
Top