Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Copy a file that is being used by another process

  1. Dec 19, 2014 #1
    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 ?
     
  2. jcsd
  3. Dec 19, 2014 #2

    jedishrfu

    Staff: 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.
     
  4. Dec 19, 2014 #3
    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.
     
  5. Dec 19, 2014 #4

    jedishrfu

    Staff: 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
     
  6. Dec 19, 2014 #5

    DaveC426913

    User Avatar
    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
     
  7. Dec 19, 2014 #6
    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.
     
  8. Dec 19, 2014 #7

    DaveC426913

    User Avatar
    Gold Member

    I am riffing off jedishr's suggestion that might allow it.
     
  9. Dec 19, 2014 #8

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    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.
     
  10. Dec 21, 2014 #9

    FactChecker

    User Avatar
    Science Advisor
    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: Dec 21, 2014
  11. Dec 22, 2014 #10
    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!
     
  12. Dec 24, 2014 #11

    jim mcnamara

    User Avatar

    Staff: Mentor

  13. Jan 6, 2015 #12

    harborsparrow

    User Avatar
    Gold Member

    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.
     
  14. Apr 12, 2015 #13
    In the Windows command prompt try

    Code (Text):
    cd <file_path>
    del <file_name> /a:s
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Copy a file that is being used by another process
  1. Image file processing (Replies: 18)

Loading...