开发者

Use the Windows raw access APIs to directly access the USB drive

开发者 https://www.devze.com 2023-03-08 09:22 出处:网络
At the end of USB physical drive, I want to write data directly using windows raw access API. I don\'t want to use kernel driver to do that.

At the end of USB physical drive, I want to write data directly using windows raw access API. I don't want to use kernel driver to do that.

As far as I know, HDD direct access is blocked from windows xp sp2 or sp3(?) for security reason. I'm not sure this is true开发者_如何学Go for USB drive.

Please guide me how to get there. Thanks a lot.


It depends on how "direct" you want to be.

Something like

HANDLE hDrive = CreateFile("\\\\.\\F:", ...);
ReadFile(hDrive, ...);

should get you what you need in most situations, although you might need DeviceIoControl with

  • IOCTL_USB_USER_REQUEST with USBUSER_PASS_THRU

  • IOCTL_SCSI_PASS_THROUGH_DIRECT

  • or IOCTL_ATA_PASS_THROUGH_DIRECT

if you're doing something really advanced.

P.S.: This should be on StackOverflow, as other people have mentioned.


Voted to move to Stack Overflow. I think regardless, using an external HDD connected by USB won't change anything, as it still appears as a normal disk to windows.

When you say "raw access API", do you mean functions like CreateFile, WriteFile etc as listed here? Because those functions should be able to be called from normal Win32 apps. Or do you want direct access to the disk itself, with no filesystem layer in between? (Some user apps such as HxD can directly open disks for reading/writing - use with caution)

0

精彩评论

暂无评论...
验证码 换一张
取 消