Announcement

Collapse
No announcement yet.

Monitor File For Read Access

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Monitor File For Read Access

    I'm looking for a way to detect when a given file is accessed for read by another process?

    I have a photobooth software application that reads a file "Processing.jpg"

    When that happens I know that a picture will be saved as I need to run a custom process on it and then print.

    Is this possible?



  • #2
    Hi Steve,


    what exactly do you need: monitoring a file read or monitoring a file write (>>>I know that a picture will be saved)? In general both is possible. But the best "how to" depends on your the situation. Do you know the name or the directory of the file to be saved ? This would make it easier.

    Look for these APIs: "ReadDirectoryChangesW" or "FindFirstChangeNotification" or poll for the last access time with "GetFileTime".


    JK

    Comment


    • #3
      Yes need to monitor the file to detect when the Breeze software reads it. I will the know that an image file is created. I do know the directory that the image will be stored in so I can monitor it manually. I did try GetFileTime LastAccessTime but that didn't seem to work (the value never changes even if I open it in photoshop)

      Comment


      • #4
        Can you get the process id of the other process (breeze) or the name of its window?
        Just wondering if something like Process Explorer is able to do.
        https://technet.microsoft.com/en-us/...sexplorer.aspx

        Comment


        • #5
          Actually this example will do the job

          https://forum.powerbasic.com/forum/u...he-file-system

          It shows the path of the file created so I can filter that for what I need.

          Comment


          • #6
            I'm looking for a way to detect when a given file is accessed for read by another process?

            I have a photobooth software application that reads a file "Processing.jpg"

            When that happens I know that a picture will be saved as I need to run a custom process on it and then print.

            Is this possible?
            It shows the path of the file created so I can filter that for what I need.
            How did you monitor for a file change when the other process is just reading or did you do something else?
            So you had a new file created by the other software that you could monitor?

            I guess you just looked for processing.jpg?

            Comment


            • #7
              Spoke too soon. That works but it doesn't show the path / file name when the software creates a file.

              Outputs this

              Code:
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -
              SHCNE_CREATE -

              Comment


              • #8
                Hi Steve,
                In SHChangeNotifyRegister DDT and SHChangeNotifyRegister SDK

                Change
                IF p(1) THEN SHGetPathFromIDList(@p(0), zPath2)
                to
                IF p(1) THEN SHGetPathFromIDList(@p(1), zPath2)

                And change
                IF p(1) THEN SHGetPathFromIDList(p(0), zPath2)
                to
                IF p(1) THEN SHGetPathFromIDList(p(1), zPath2)

                Code is updated...

                Pierre

                Comment


                • #9
                  Originally posted by Pierre Bellisle View Post
                  Code is updated...

                  Pierre
                  They both have a memory leak too since they never free the pidl from SHGetSpecialFolderLocation. I know it doesn't actually matter for the example, but still, if you're fixing it...

                  Comment


                  • #10
                    With current Windows OS, better to use KNOWNFOLDERID

                    Something like that
                    Code:
                    WCHAR* SH_FolderGet(IN KNOWNFOLDERID rfid) {
                        static WCHAR path[MAX_PATH];
                        ZeroMemory(path, MAX_PATH * sizeof(WCHAR));
                        PWSTR pPath[MAX_PATH];
                        if (SHGetKnownFolderPath(rfid, 0, NULL, pPath) == 0) {
                            wcscpy(path, *pPath); PathAddBackslash(path);
                            CoTaskMemFree(*pPath);
                        }
                        return path;
                    }
                    Patrice Terrier
                    www.zapsolution.com
                    www.objreader.com
                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                    Comment


                    • #11
                      Q> They both have a memory leak too since they never free the pidl from SHGetSpecialFolderLocation.

                      Hi Bob,

                      Not exactly, SHGetPathFromIDList's leak is not related to SHGetSpecialFolderLocation leak.
                      You need to free SHGetSpecialFolderLocation for itself
                      and you need to free one or both SHGetPathFromIDList depending on result.
                      I will clean up the code later. DDT and SDK...

                      -

                      Hey Pat,

                      As we know SHGetSpecialFolderLocation still work fine, even in Windows 10 if I remember correctly.
                      But it's not a bad idea to respect Bill's recommendation.
                      I will use SHGetKnownFolderIDList instead of SHGetSpecialFolderLocation in the cleaned code.
                      XP user may unRem and use SHGetSpecialFolderLocation instead.

                      -

                      Steve,
                      If the problem persist with the newer code, and you feel like it,
                      please post some minimal code that show the bad behavior.

                      Pierre
                      Last edited by Pierre Bellisle; 20 May 2017, 12:23 AM.

                      Comment

                      Working...
                      X