Hi Everybody.

I'm new to Win32asm programming but did a bit of Tasm many moons ago. Anyhow, I am learning Win32asm though Iczelion's great set of tutorials and have got to the part about creating and handling files. To experiment with this I wrote a little app to copy a file to a USB pen drive. On my PC the pen drive always mounts as the same letter, so my program copies the file from one drive to the other. Well, I have to start somewhere.

Can I add functionality to my program to check that the destination drive is a pen drive? Does anyone know what API calls I should investigate to detect if the pen drive is present in the system?

If the detection and identification of USB pen drives is ultra complex, please let me know and I'll continue with the tutorial and come back to it later.

Posted on 2005-03-29 05:10:20 by Lightman
I wish I knew how to do this :/

If you use QueryDosDevice, you will get a string like \Device\Harddisk5\DP(1)0-0+10 which can perhaps be useful for some further querying (haven't looked into it). Otherwise, the best bet is probably GetDriveType, which should return DRIVE_REMOVABLE for pendrives.
Posted on 2005-03-29 07:09:57 by f0dder
I use WNetOpenEnum & WNetEnumResource ( all WIN32 OSes ) to parse mapped sources.? But you may need to do more research to determine if that resource is a pen drive.? I got working code for my parser on this if you want it.?

Ask for it on http://www.masmforum.com  Seeing, I don't check here regularly enough.

Regards,? P1? 8)
Posted on 2005-03-29 09:42:07 by Pone
Pone, does that work for local stuff as well? And could you post the source here - I don't really want to go to that evil place ;)
Posted on 2005-03-29 10:13:26 by f0dder
Thanks Guys,

I have been playing with GetDriveType which does return the value for removable disk. For the time being I can check the pen device by ensuring that it is a removable device and not a floppy disk drive. In the furture I would like to return the name of the device and check that it is a USB pen, but given that I have just learnt how to create a file in win32asm, I am getting ahead of myself a bit.

If anyone out there comes accross info of USB programming, would you pass it on.


Posted on 2005-03-30 07:25:38 by Lightman
How do you check that it's not a floppy drive?
Posted on 2005-03-30 08:39:45 by f0dder

For the time being I am going to cheat. Via the user interface I can ask for the drive to copy the file to, if the user selects A or B then I can trap that input in my code.

It will work, but you just know that there would be someone out there who maps a floppy to f:\ or something.


Posted on 2005-03-30 09:06:48 by Lightman
>>It will work, but you just know that there would be someone out there who maps a floppy to f:\ or something.

There's always someone whos going to try to break it by feeding it the wrong data. You can't make it right for everyone out there trying to break it. If I was you I'd just ask the user for where to save it and let it go after that.

If you 'have to' have it save on a removable drive, just go the easy way and enumerate drives using GetDriveType starting after "C" and list up the removable ones. Save the user choice as standard and let it go.

If there's ever someone emailing you claiming he mounted a floppy on K: and then chose it to save there, just put him on your ignore list. :)

Posted on 2005-03-30 10:05:45 by JimmyClif