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


                      • #12
                        I did try GetFileTime LastAccessTime but that didn't seem to work (the value never changes even if I open it in photoshop)

                        There are some 'gotchas' with Last Access Time..

                        file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 (UTC). The system records file times whenever applications create, access, and write to files. Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. [Bold text mine. MCM]
                        Source: SDK on disk. Under Topic "File times" which may be where you could find it on line @ msdn.com

                        Also... failing code not shown.


                        Michael Mattias
                        Tal Systems Inc.
                        Racine WI USA
                        mmattias@talsystems.com
                        http://www.talsystems.com

                        Comment


                        • #13
                          Yes need to monitor the file to detect when the Breeze software reads it.
                          Does Breeze (never heard of it) offer an API which might provide a notification of some kind?:

                          Have you even considered this option and checked it out instead of thinking of watching files on disk and then just stopping looking for 'another way?'

                          MCM
                          Michael Mattias
                          Tal Systems Inc.
                          Racine WI USA
                          mmattias@talsystems.com
                          http://www.talsystems.com

                          Comment


                          • #14
                            https://breezesys.com/Photobooth/index.htm

                            The software is a bit clunky so to speak and quite difficult to configure unless your a geek!

                            I think that this is a perfect project that could be written in powerbasic. Combining the GRAPHIC command and combine with the use of image magick http://www.imagemagick.org/script/index.php

                            Most of the chroma key stuff is easy in image magick although would need yo be able to do live preview of green screen so user can see the picture that's about to be taken.

                            Also it seems that breeze has a notification. I had a reply from their technical support.

                            I have had a look into the Breeze question you asked relating to the automatic opening of an application. There maybe something you can make use of in the "Setup Image Editor " menu within the file tab of Breeze. This may enable you to allow Breeze to call an application after the capture process is complete. I.e your script. You can enter the relevant command lines within this tab.

                            Comment

                            Working...
                            X