Receive alert when a file is accessed...-VBForums
Results 1 to 9 of 9

Thread: Receive alert when a file is accessed...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Exclamation 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.

  2. #2
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,791

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    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?".

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    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.

  8. #8
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,065

    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 ?

  9. #9
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,791

    Re: Receive alert when a file is accessed...

    Quote Originally Posted by Conroy Vanderbluff View Post
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.