Re: reading a sector on USB memory stick

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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"

.



Relevant Pages

  • Re: reading a sector on USB memory stick
    ... 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 ...
    (microsoft.public.vb.general.discussion)
  • reading a sector on USB memory stick
    ... 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 ...
    (microsoft.public.vb.general.discussion)
  • Re: reading a sector on USB memory stick
    ... 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 ...
    (microsoft.public.vb.general.discussion)
  • Re: SP2 Installation Problem
    ... >something, with modern IDE drives, Windows will never see a bad sector ... If there are problems with a sector, ... >place on the drive, all transparent to Windows. ... If either flag is set, an automatic check of the file system ...
    (microsoft.public.windowsxp.general)
  • Re: OT: fdisk
    ... BIOS sector numbering starts with sector 1 ... The data for partition 1 is: ... CHS terms), looks correct for s1, one slice, whole disk for NTFS. ... windows plays strange tricks the way it layers directories for display. ...
    (freebsd-questions)