I would like to modify this so it would check every 5 seconds to see if I have plugged in a thumb drive.
Then it could copy some backup files to it.
I realize that it would have to stay in memory. As long as it did not use a lot of resouces.
How could I do that?
Thanks.
Then it could copy some backup files to it.
I realize that it would have to stay in memory. As long as it did not use a lot of resouces.
How could I do that?
Thanks.
invoke CreateFile,CTEXT("f:\result.txt"), 0, FILE_SHARE_READ or FILE_SHARE_WRITE, \
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
.IF (eax==INVALID_HANDLE_VALUE)
invoke MessageBox, 0, CTEXT("Thumb drive not plugged in."), CTEXT(" "), MB_OK
invoke ExitProcess, -1
.else
invoke MessageBox, 0, CTEXT("USB drive is F:"), CTEXT(" "), MB_OK
.ENDIF
Polling sucks - I think this is what you want to look at. Also, hardcoding drive letters won't work, as USB devices don't always get assigned the same letter.
You can have it running silently in the background without a GUI, or you can add a tray notification icon, or whatever - there's plenty of choices.
I realize that it would have to stay in memory. As long as it did not use a lot of resouces.
How could I do that?
Simple - don't terminate your app :)How could I do that?
You can have it running silently in the background without a GUI, or you can add a tray notification icon, or whatever - there's plenty of choices.
Can't thumb drives have an autorun ? Why not have your app get started with the thumb drive and back up data to it ?
Can't thumb drives have an autorun ? Why not have your app get started with the thumb drive and back up data to it ?
They can, but autorun has been disabled on anything but optical media on recent windows versions for security issues.
Good call ! Was also a tad annoying.
@Skywalker: What do you need to backup? As f0dder said polling isn't the way to go and drive letters may change. I use a combination of MSBackup and Windows Live Sync (formerly foldershare) to create and store it remotely.
I believe there are also online backup services which could provide some services for you : https://mozy.com/ Afaik they set up a desktop folder client thingy and backs up whatever changes. 2GB Free for home users.
no need to poll, its the wrong way to do it it...
simply handle the WM_DEVICECHANGE message
http://msdn.microsoft.com/en-us/library/aa363480%28VS.85%29.aspx
this would be the proper way to do it, using less resources too :)
once you get the message you want, then do the checking
note. that when you get the message, the system may not have fully initialised the unit, so wait a little
(i usually wait ~30 seconds) and then do the check, set a flag then to check again (in a reasonable
amount of time), and unset this flag if you get the removal message (you might also want to make some
of the flags global, so you can check them in the routine doing the backup.. )
simply handle the WM_DEVICECHANGE message
http://msdn.microsoft.com/en-us/library/aa363480%28VS.85%29.aspx
this would be the proper way to do it, using less resources too :)
once you get the message you want, then do the checking
note. that when you get the message, the system may not have fully initialised the unit, so wait a little
(i usually wait ~30 seconds) and then do the check, set a flag then to check again (in a reasonable
amount of time), and unset this flag if you get the removal message (you might also want to make some
of the flags global, so you can check them in the routine doing the backup.. )
They can, but autorun has been disabled on anything but optical media on recent windows versions for security issues.
Good call ! Was also a tad annoying.
@Skywalker: What do you need to backup? As f0dder said polling isn't the way to go and drive letters may change. I use a combination of MSBackup and Windows Live Sync (formerly foldershare) to create and store it remotely.
I believe there are also online backup services which could provide some services for you : https://mozy.com/ Afaik they set up a desktop folder client thingy and backs up whatever changes. 2GB Free for home users.
My main backup is to a 2nd hard drive, but it would be nice to be able to detect when I have plugged my thumbdrive in and have files copied to it without having to run a batch file to do it.
Andy
Thanks.
It looks like I will need to use both WM_DeviceChange and DBT_DEVICEARRIVAL.
Andy
It looks like I will need to use both WM_DeviceChange and DBT_DEVICEARRIVAL.
Andy
no need to poll, its the wrong way to do it it...
simply handle the WM_DEVICECHANGE message
Nice ! Once you know the answer it all makes sense :)
Polling sucks - I think this is what you want to look at. Also, hardcoding drive letters won't work, as USB devices don't always get assigned the same letter.
This has been truly helpful! I did not know about this, and didn't know I needed it, until I saw this. I have now used it in two projects to replace a less efficient method. Thank you for this post!
Another tool for my toolbelt.
farrier
Polling sucks - I think this is what you want to look at. Also, hardcoding drive letters won't work, as USB devices don't always get assigned the same letter.
This has been truly helpful! I did not know about this, and didn't know I needed it, until I saw this. I have now used it in two projects to replace a less efficient method. Thank you for this post!
its 2k or later :) msdn stated it
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
its 2k or later :) msdn stated it
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server