-
Oct 5th, 2015, 08:09 PM
#1
Thread Starter
Addicted Member
Receive alert when a file is accessed...
I'd like to know when a particular file (no matter the filetype) is accessed, providing an alert like, say, a MsgBox.
-
Oct 5th, 2015, 10:07 PM
#2
Re: Receive alert when a file is accessed...
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.
-
Oct 6th, 2015, 09:05 AM
#3
Thread Starter
Addicted Member
Re: Receive alert when a file is accessed...
Your code seems to cause an error in the "StartNotify" public function here:
Code:
Call SHGetSpecialFolderLocation(CSIDL_DESKTOP, pidlDesktop)
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?
I'm using Windows 7 64-bit
-
Oct 6th, 2015, 09:14 AM
#4
Thread Starter
Addicted Member
Re: Receive alert when a file is accessed...
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.
-
Oct 6th, 2015, 09:16 AM
#5
Thread Starter
Addicted Member
Re: Receive alert when a file is accessed...
Okay, I see it now. Just looking for the spot to make the change to watch only one file now.
-
Oct 6th, 2015, 09:25 AM
#6
Thread Starter
Addicted Member
Re: Receive alert when a file is accessed...
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?".
-
Oct 6th, 2015, 10:01 AM
#7
Thread Starter
Addicted Member
Re: Receive alert when a file is accessed...
It also doesn't seem to handle when a file is accessed using another program. Oh well.
-
Oct 6th, 2015, 06:37 PM
#8
Re: Receive alert when a file is accessed...
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 ?
-
Oct 6th, 2015, 07:52 PM
#9
Re: Receive alert when a file is accessed...
Originally Posted by Conroy Vanderbluff
Your code seems to cause an error in the "StartNotify" public function here:
Code:
Call SHGetSpecialFolderLocation(CSIDL_DESKTOP, pidlDesktop)
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?
I'm using Windows 7 64-bit
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|