Home All Groups Group Topic Archive Search About

reading a sector on USB memory stick

Author
12 Jun 2009 5:58 PM
Bu
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?
Bu

Author
12 Jun 2009 9:37 PM
MikeD
"Bu" <s*@si.si> wrote in message
news:kf5535pb3lelka6hcljuoej5ht58v3svad@4ax.com...
> 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.


You mean a specific sector?  I don't think you can do that with VB. This
would require very low-level disk access. Possibly there's such an API
function that you could call from VB, but I have doubts.

Out of curiosity, would you mind explaining why you need to do this?

--
Mike
Author
12 Jun 2009 9:39 PM
Jeff Johnson
"Bu" <s*@si.si> wrote in message
news:kf5535pb3lelka6hcljuoej5ht58v3svad@4ax.com...

> 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?

That kind of access is too low-level for VB. You'd have to have some
specialized DLL (most likely written in C[++]) which your VB program could
utilize. In other words, VB itself is not going to do this.
Author
12 Jun 2009 10:41 PM
Jim Mack
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"
Author
14 Jun 2009 11:20 AM
Bu
On Fri, 12 Jun 2009 19:58:27 +0200, Bu <s*@si.si> 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?
>Bu
FYI
On http://www.vbforums.com/showthread.php?p=3538536#post3538536
I got some information that might be of interest to you.
Bu