Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. check when a file is opened on windows
Forum Updated to NodeBB v4.3 + New Features

check when a file is opened on windows

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.5k Views 2 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    Hello
    I want to check if the file is opened or started on windows something like file system watcher for example.
    I am using file system watcher to check any change in the dir or a file but it not change or give a signal when it opened so if there is something similar to detect when the file is opened or started.
    I have many shortcuts for a programme so I want to watch those files and detect which one is opened by the user like the file system watcher.
    Thanks in advance.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      You mean like the QFileSystemWatcher class? Or do you mean using the winapi to do it directly? In which case just google "watch file for change winapi c++" or something and you should find code to do it.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      3
      • AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        @ambersharkI mean the way it works to give it a file and when the user just double-clicks it to open that file it emits a signal with the file name.
        use windows API use qt both are fine the main thing is to get this file name.

        JonBJ 1 Reply Last reply
        0
        • AmrCoderA AmrCoder

          @ambersharkI mean the way it works to give it a file and when the user just double-clicks it to open that file it emits a signal with the file name.
          use windows API use qt both are fine the main thing is to get this file name.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @AmrCoder
          http://doc.qt.io/qt-5/qfilesystemwatcher.html#details

          The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications.

          Opening a file/starting an executable does not modify a file. QFileSystemWatcher will not help, and there is no "signal" emitted in Windows (or for that matter Linux) when a file is simply opened. So you will not be able to detect that via these means.

          A 1 Reply Last reply
          2
          • AmrCoderA Offline
            AmrCoderA Offline
            AmrCoder
            wrote on last edited by
            #5

            Yes, I know so what iam asking is if there is an alternative or library which do this it can be not in QT if anyone does something like this before.

            JonBJ 1 Reply Last reply
            0
            • AmrCoderA AmrCoder

              Yes, I know so what iam asking is if there is an alternative or library which do this it can be not in QT if anyone does something like this before.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @AmrCoder
              And since I wrote that the Windows OS does not issue some "signal" or "notification" whenever a file is "opened", you're not going to be able to do it, Qt or not, I believe.

              Have a look at, say, https://social.msdn.microsoft.com/Forums/vstudio/en-US/5752e234-6429-456c-bbd0-a2bbf49c5914/filesystemwatcherchanged-event-does-it-fire-when-a-file-is-accessed or https://www.daniweb.com/programming/software-development/threads/241214/help-with-open-file-notification if you don't believe me...

              1 Reply Last reply
              0
              • JonBJ JonB

                @AmrCoder
                http://doc.qt.io/qt-5/qfilesystemwatcher.html#details

                The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications.

                Opening a file/starting an executable does not modify a file. QFileSystemWatcher will not help, and there is no "signal" emitted in Windows (or for that matter Linux) when a file is simply opened. So you will not be able to detect that via these means.

                A Offline
                A Offline
                ambershark
                wrote on last edited by ambershark
                #7

                @JonB Oh wow, yea I misread the OP's post. I thought they wanted to watch for changes but in Windows rather than linux.

                @AmrCoder You should be able to detect a file open since ProcMon from sysinternals does it. I'm not much of a windows guy so I can't tell you how to do it, just that it's possible since at least one app does it. :)

                Edit: my guess would be some kind of system hook that detects any sort of file access including opening it for read. You will need admin for your application to do this. Probably not a great idea, and you may want to find some other way to do what you're trying to do.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved