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

北慕城南 提交于 2019-12-23 17:43:23

问题


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 for USB drive.

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


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/6106874/use-the-windows-raw-access-apis-to-directly-access-the-usb-drive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!