File is used by another process. How to know which process?
Asked Answered
P

4

9

I keep getting that exception in my program. How do I know which process locked it, either by program code or by doing something with windows?

System.IO.IOException : The process cannot access the file 'file.ext' because it is being used by another process.

Pampuch answered 2/8, 2010 at 8:30 Comment(0)
O
12

You can use ProcessExplorer to search for the file:

Just run that (maybe you need to launch it with administrator rights), hit Ctrl-F and type in the name of the file which is locked - it will find all open handles which match the given name, and tell you which process it belongs to.

Owl answered 2/8, 2010 at 8:36 Comment(3)
how do I know which process is currently using the file? because when I tried it it looks like it list all recent accessesPampuch
@Louis RH: after starting of the Process Explorer under an account with administrative rights you should press Ctrl-F or choose in the menu "Find" / "Find Handle or DLL..." and then type the name of the file which you search. So just do exactly what Kragen wrote for you.Reflux
@Louis - It may be that processes that access that file don't close it immediately, in which case Process Explorer will find those handles / processes for you - I'm not sure how to work out which of those handles is blocking your use of that file however (not all Handles will block access to a file - two processes can share the same file depending on the access that each process requested - read/write etc...)Owl
H
3

You can use a tool like ProcessMon to see what process is locking a file.

Hickory answered 2/8, 2010 at 8:33 Comment(1)
This was the only feasible option in my case compared to ResourceMonitor and ProcessExplorer which both assume the blocking application still has a hold of the file by the time I get around to looking up who's blocking on it. In my case I was caught in some temp file switcharoo with MSBuild and apparently mcshield.exe who was doing mischief with my prebuild commands that write to temp batch files.Significative
T
1

Have a look at this: http://www.emptyloop.com/unlocker/

I use it all the time, tells you which process has locked it and gives you the chance to unlock it fully. Useful especially for when your debugging image manipulation apps and it bombs out without closing the file properly.

Hope this helps!

Sean

Tigerish answered 2/8, 2010 at 8:32 Comment(0)
C
-1

The error message you're encountering indicates that the file you're trying to delete is currently in use by another process. Here are a few steps you can take to resolve this issue:

  1. Identify and Stop the Process You need to identify which process is using the file and stop it. You can do this using the built-in Windows utility Resource Monitor or a third-party tool like Process Explorer.

Using Resource Monitor: Open Resource Monitor by typing resmon in the Start menu search bar and pressing Enter. Go to the CPU tab. Use the Associated Handles search box to find your file Identify the process holding the handle and end it. Using Process Explorer: Download and run Process Explorer from the Microsoft website. Press Ctrl+F to open the search dialog. Search for the file . Identify the process holding the handle and end it.

Clinkstone answered 2/8 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.