Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Which process is using a file i want to delete / update?

Which process is using a file i want to delete / update?

Scheduled Pinned Locked Moved C / C++ / MFC
comjsonhelpquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wolfgangpuelm
    wrote on last edited by
    #1

    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.

    I L 2 Replies Last reply
    0
    • W wolfgangpuelm

      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.

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • W wolfgangpuelm

        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.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups