Re: reading a sector on USB memory stick
- From: "Jim Mack" <jmack@xxxxxxxxxxxxxxx>
- Date: Fri, 12 Jun 2009 18:41:53 -0400
Bu wrote:
Hello,
I need to write an VB6 application for reading and writing a sector
on a USB memory stick in a Windows XP system.
I looked arounf for some sample code but was not succesful in
locating anything.
Anybody any suggestions?
Windows, at least the NT-variants like 2K / XP etc, allow you to open
many block devices as though they were files, using CreateFile.
Use the syntax \\.\X: (where X is the drive letter) to get access to
the block device at the sector level.
For example,
hDevice = CreateFile("\\.\E:", _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
0, _
OPEN_EXISTING, _
0, _
0)
If this succeeds, hDevice can be used with ReadFile to read specific
portions of the disk.
You may need to first Lock the device to get raw access, and you
should only request the access you need -- don't ask for GENERIC_WRITE
access if you don't need it.
The example shown passes a null SECURITY_DESCRIPTOR, which is another
potential point of failure. You may need to explicitly pass a
descriptor that allows the user the specific permissions needed.
Good luck!
--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"
.
- References:
- reading a sector on USB memory stick
- From: Bu
- reading a sector on USB memory stick
- Prev by Date: Re: How to wrap a callback for VB6
- Next by Date: Re: Ghost Form
- Previous by thread: Re: reading a sector on USB memory stick
- Next by thread: Re: reading a sector on USB memory stick
- Index(es):
Relevant Pages
|