I'd like to know when a particular file (no matter the filetype) is accessed, providing an alert like, say, a MsgBox.
Printable View
I'd like to know when a particular file (no matter the filetype) is accessed, providing an alert like, say, a MsgBox.
You'll probably want to use SHChangeNotifyRegister; here's an example I just happened to make the other day. The example watches the whole file system, but you can specify a folder. Then just watch for events on your target file, like SHCNE_UPDATEITEM, SHCNE_DELETE, SHCNE_RENAMEITEM, etc.
Your code seems to cause an error in the "StartNotify" public function here:
and then crashes VB6 when attempting to Stop the project from running. I downloaded the .zip file included in the thread you linked to. Perhaps you could update it if you have a better version or even post it here in this thread?Code:Call SHGetSpecialFolderLocation(CSIDL_DESKTOP, pidlDesktop)
I'm using Windows 7 64-bit
Okay... instead of using the .zip file on that thread, I just copied and pasted what you wrote to begin with and it doesn't crash, yet I'm not sure what, exactly, it is watching for changes.
Okay, I see it now. Just looking for the spot to make the change to watch only one file now.
Hmm... it seems it would be easier to just watch the "%appdata%/Microsoft/Windows/Recent" folder for additions. That's good, but I'd also like to know when the file stops being accessed. For instance, "Is this .mp3 file being used?" and "Has it stopped being used?".
It also doesn't seem to handle when a file is accessed using another program. Oh well.
It may not effect the solutions members are posting, but can you define what you mean exactly (and completely) when you say "is accessed" ?
What exactly are you trying to do ?
Forgot an argument, should be 0, CSIDL_DESKTOP, pidlDesktop.. sorry about that. I fixed the zip but you can just add that argument in to fix it in code. Some people..ahem..don't like the VarPtr(0) shortcut for pidlDesktop.
The project does use subclassing, so you can't use the stop button. Always exit it by closing the window normally to avoid a crash.