Solved check when a file is opened on windows
-
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. -
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.
-
@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. -
@AmrCoder
http://doc.qt.io/qt-5/qfilesystemwatcher.html#detailsThe 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. -
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.
-
@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...
-
@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.