can't write to physical drive in win 7? <p>I wrote a disk utility that allowed you to erase whole physical drives. it uses the windows file api, calling :</p> <pre><code>destFile = CreateFile("\\\\.\\PhysicalDrive1", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,createflags, NULL); </code></pre> <p>and then just calling <code>WriteFile</code>, and making sure you write in multiples of sectors, i.e. 512 bytes.</p> <p>this worked fine in the past, on XP, and even on the Win7 RC, all you have to do is make sure you are running it as an administrator. </p> <p>but now I have retail Win7 professional, it doesn't work anymore! the drives still open fine for writing, but calling <code>WriteFile</code> on the successfully opened Drive now fails!</p> <p>does anyone know why this might be? could it have something to do with opening it with shared flags? this is always what I have done before, and its worked. could it be that something is now sharing the drive? blocking the writes? is there some way to properly "unmount" a drive, or at least the partitions on it so that I would have exclusive access to it? </p> <p>some other tools that used to work don't any more either, but some do, like the WD Diagnostic's erase functionality. and after it has erased the drive, my tool then works on it too! leading me to believe there is some "unmount" process I need to be doing to the drive first, to free up permission to write to it. </p> <p>Any ideas?</p> <p>Update:</p> <p>the error code returned from <code>WriteFile</code> is '5', <code>ERROR_ACCESS_DENIED</code> but again, if I 'erase' the drive first using WD Diag, I can then access and write to the drive fine. when I initialize the drive again, and give it a partition, I go back to getting the <code>ERROR_ACCESS_DENIED</code> error.</p>