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. File monitor

File monitor

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonquestion
8 Posts 4 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.
  • S Offline
    S Offline
    suzuuu
    wrote on last edited by
    #1

    Hi, How can i get file status(ie. open, close, edit) using C or C++. Is there any API in windows. Thanks in advance Suzu

    M S S 3 Replies Last reply
    0
    • S suzuuu

      Hi, How can i get file status(ie. open, close, edit) using C or C++. Is there any API in windows. Thanks in advance Suzu

      M Offline
      M Offline
      Michel Godfroid
      wrote on last edited by
      #2

      A file is either opened or closed by one or more processes. The mode in which it is open is a characteristic of the handle, which is owned by a process, not the file. (not all handles are owned by processes, but let's keep this simple.) The bad news is: there is no API. You could have a go at the object manager[^] name space, but this requires the openfiles global flag to be on. Turning it on or off will require a reboot. Short of that, you can only obtain the information in kernel mode, and that will require a device driver.

      1 Reply Last reply
      0
      • S suzuuu

        Hi, How can i get file status(ie. open, close, edit) using C or C++. Is there any API in windows. Thanks in advance Suzu

        S Offline
        S Offline
        sashoalm
        wrote on last edited by
        #3

        Do you mean the context menu of a file by this "file status(ie. open, close, edit)", or do you mean if a file can be accessed, opened for reading/writing, etc.? You can do that by calling _open[^]

        There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

        S 1 Reply Last reply
        0
        • S sashoalm

          Do you mean the context menu of a file by this "file status(ie. open, close, edit)", or do you mean if a file can be accessed, opened for reading/writing, etc.? You can do that by calling _open[^]

          There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

          S Offline
          S Offline
          suzuuu
          wrote on last edited by
          #4

          Just i want to get current status of the file. ie. 1) It is opend 2) It is Closed 3) It is modified Thanx

          S 1 Reply Last reply
          0
          • S suzuuu

            Hi, How can i get file status(ie. open, close, edit) using C or C++. Is there any API in windows. Thanks in advance Suzu

            S Offline
            S Offline
            Software_Developer
            wrote on last edited by
            #5

            Accessing File Status (MFC) Also, you can try CFile::GetStatus

            CFile theFile;
            char* szFileName = "X:\\TEXT.TXT";
            BOOL bOpenOK;

            CFileStatus status;
            if( CFile::GetStatus( szFileName, status ) ) bOpenOK = theFile.Open( szFileName, CFile::modeWrite );
            else bOpenOK = theFile.Open( szFileName, CFile::modeCreate | CFile::modeWrite );

            http://msdn.microsoft.com/en-us/library/e3z63bza(VS.80).aspx[^] .

            S 1 Reply Last reply
            0
            • S Software_Developer

              Accessing File Status (MFC) Also, you can try CFile::GetStatus

              CFile theFile;
              char* szFileName = "X:\\TEXT.TXT";
              BOOL bOpenOK;

              CFileStatus status;
              if( CFile::GetStatus( szFileName, status ) ) bOpenOK = theFile.Open( szFileName, CFile::modeWrite );
              else bOpenOK = theFile.Open( szFileName, CFile::modeCreate | CFile::modeWrite );

              http://msdn.microsoft.com/en-us/library/e3z63bza(VS.80).aspx[^] .

              S Offline
              S Offline
              suzuuu
              wrote on last edited by
              #6

              yeah... but i need pure win32 API or any library function.

              S 1 Reply Last reply
              0
              • S suzuuu

                yeah... but i need pure win32 API or any library function.

                S Offline
                S Offline
                Software_Developer
                wrote on last edited by
                #7

                Sorry about that. This link below got truckloads of API's to hook your app on for "monitoring" http://win32-hook.vista-files.org/[^]

                1 Reply Last reply
                0
                • S suzuuu

                  Just i want to get current status of the file. ie. 1) It is opend 2) It is Closed 3) It is modified Thanx

                  S Offline
                  S Offline
                  sashoalm
                  wrote on last edited by
                  #8

                  You need to be more clear. 1) A file might be opened in the sense that there are handles of that file opened by one or more processes. 2) I don't know what you mean by "closed", is it that no process has opened the file currently? 3) A file has always been modified somewhere in the past, it might be a minute ago or a month ago or 10 years ago. That's how you create a file, you create it empty and then modify it. Do you mean that you want to get the date of last modification? What do you mean by "it is modified"?

                  There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

                  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