Which process is using a file i want to delete / update?
-
Hi everybody, I'm looking for the (WIN32) API to find out which process is currently using a file i'm just trying to delete or update. There's a great tool called FileMon in sysinternals.com, but unfortunately the source isn't available (although it's free). It would be a great help if some one might have an idea at least where to start with to get this info. Thanks in Advance! Wolfgang.
-
Hi everybody, I'm looking for the (WIN32) API to find out which process is currently using a file i'm just trying to delete or update. There's a great tool called FileMon in sysinternals.com, but unfortunately the source isn't available (although it's free). It would be a great help if some one might have an idea at least where to start with to get this info. Thanks in Advance! Wolfgang.
From memory, there used to be a dll called PSAPI which may help - but I don't know if it's still valid. Alternately, it's quite possible there isn't a nice Win32 api. I know some of the sysinternals software launches a device driver to do its work, to communicate with the kernel - which is where the handles all end up. Iain
-
Hi everybody, I'm looking for the (WIN32) API to find out which process is currently using a file i'm just trying to delete or update. There's a great tool called FileMon in sysinternals.com, but unfortunately the source isn't available (although it's free). It would be a great help if some one might have an idea at least where to start with to get this info. Thanks in Advance! Wolfgang.
Hi, FYI: if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted. The other process very likely is some server code that is there to assist you somehow. Candidates are: - anti-virus software (Norton, McAfee, whatever) - indexing software (Google Desktop, MS Office, whatever) The common thing is these packages are looking all the time for new files, so they can inspect them. Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one-second interval), and only reports failure if the action continues to fail for that time. The solution: 1. either use a different file name 2. or remove all background reader candidates (bad idea) 3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this) BTW: if all you need is Read, make sure to allow others to read as well, i.e. use File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read) :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets