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. How to tell if a file is open by someone else

How to tell if a file is open by someone else

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestionjsonhelptutorial
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.
  • G Offline
    G Offline
    GeraldoLuiz
    wrote on last edited by
    #1

    I have a program that manages documents on a central area in the network and I need to tell if a file is in use by someone ele, when I try to open it. The program runs on each machine that access the central archive (no program runs on the server that holds the files). What is the right or the best way to do it ? Can I try to lock the file or rename it and see by the error returned if the file is open ? Is there any API function that tells me that ? If it´s a Word Doc, for instance, the Word gives me a hint, but Notepad doesn´t. I want to send my own msg to the user, despite of the app used to open the file. Is it possible ?

    N 1 Reply Last reply
    0
    • G GeraldoLuiz

      I have a program that manages documents on a central area in the network and I need to tell if a file is in use by someone ele, when I try to open it. The program runs on each machine that access the central archive (no program runs on the server that holds the files). What is the right or the best way to do it ? Can I try to lock the file or rename it and see by the error returned if the file is open ? Is there any API function that tells me that ? If it´s a Word Doc, for instance, the Word gives me a hint, but Notepad doesn´t. I want to send my own msg to the user, despite of the app used to open the file. Is it possible ?

      N Offline
      N Offline
      n 0
      wrote on last edited by
      #2

      check out sdk's CreateFile() proc. if specified file is somehow locked, you get an invalid handle. you may then call GetLastError(): hope this helps...

      B 1 Reply Last reply
      0
      • N n 0

        check out sdk's CreateFile() proc. if specified file is somehow locked, you get an invalid handle. you may then call GetLastError(): hope this helps...

        B Offline
        B Offline
        basementman
        wrote on last edited by
        #3

        or you could look at good old _sopen, passing the _SH_DENYRW flag  onwards and upwards...

        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