Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

Error 5 (ERROR_ACCESS_DENIED) when writing to a physical device

$
0
0
I'm trying to "raw write" data to a USB thumbdrive using the WriteFile API function. My thumbdrive is \\.\physicaldrive1 for the purpose of opening it with the CreateFile API function. I find that this error 5 (ERROR_ACCESS_DENIED) only appears when writing to the device (not when reading it), and even then it ONLY appears when trying to write to a sector OTHER THAN first sector (sector 0) on the device. It also only is a problem when attempting to write when I open it as a physical drive (\\.\physicaldrive1), but it has no problem writing to any place on the drive I want when I open it as a logical drive (\\.\h:). I assume this is a problem with the permissions flags I set when using the CreateFile API function.

Could someone here kindly point out what permissions flags (or possibly other flags as well) I must use in the CreateFile API function, to make all sectors writable when opening my thumbdrive as a physical drive?

Viewing all articles
Browse latest Browse all 168

Trending Articles