Monitoring file access with SHChangeNotifyRegister

I am using SHChangeNotifyRegister to monitor when someone copies files from the system to a USB stick.  The returned value is the path of the USB drive plus the name of the file.  This works fine because I know the drive letter the USB stick is mapped to.  

Now I want to monitor when files are copied FROM the USB stick.  Because the returned value is the TO address I don't know where the copied file has come from - (it could be another mapped drive).

Any ideas?
LVL 3
jdthedjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:

You must  capture globally for file and get first char. This is a drive letter.
Now you can get device/media type using and when it is DRIVE_REMOVABLE do something...

...
DriveName:='F:\';
...
if GetDriveType(PChar(DriveName)) = DRIVE_REMOVABLE then
...

Open in new window


definition of GetDriveType you can fin in jcl/jvcl delphi package or JwaWinBase.pas
windows header translation.

0
jdthedjAuthor Commented:
Thanks for the reply sinisav - I am already able to determine when a file is put onto the flash drive, but I need to know if a file is copied from there to the hard drive
0
Sinisa VukSoftware architectCommented:

Same procedure for checking DRIVE_REMOVABLE but with difference to check if
it is DRIVE_FIXED. So get source and destination drive letter and check:

...
    GetDriveType("A") = DRIVE_REMOVABLE
    GetDriveType("C") = DRIVE_FIXED
...

Open in new window

0
jdthedjAuthor Commented:
@sinisav You are not understanding the question.  I know all about the drives - I just want to know if a file has been copied from the flash drive to the hard drive.

Anyway I have found a workaround.  I fill a listbox with all the filenames from the flash drive, including subfolders, then when a file appears (is created) on another drive I check to see if it is in the list.  If it is there is a strong probability that the file came from the flash drive.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdthedjAuthor Commented:
Found my own solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.