title: WriteFile error #5 "denied access" under win Vista/seven
body: <p>I googled a lot and I couldn't find any answer to this problem...</p>
  
  <p>I have a C++ console application that reads a 1GB SD card that fixes improperly closed files and writes the FAT table accordingly. The SD card is written at the beginning by a firmware in a custom made device. 
  It worked OK up to Xp and stopped working in Win Vista/seven.
  I tried elevating privileges: within an administrator account type, I launched a cmd window using the "run as administrator" method but no luck.
  I also tried with a manifest asking for highestAvailable privileges but no luck.</p>
  
  <p>I read in some post that “Windows Vista doesn't allow you to access the disks from user-mode processes at all.  Does anybody know about any way of bypassing this behavior?</p>
  
  <p>I’m working in a workaround however I would like to know if this is impossible or not</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is my first post here so I don't quite understand about the linking issue... But I'm not reated to any spam at all... just asking in a comunity driven site :)</p>
  
  <p>The code looks like</p>
  
  <pre><code>hDevice = CreateFile(buffer,GENERIC_READ | GENERIC_WRITE,
          FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING,0,NULL); 
  </code></pre>
  
  <p>I then read the BTB information from the SD and look for and improperly closed file.</p>
  
  <p>Finally when trying to write to the SD</p>
  
  <pre><code>WriteFile(hDevice,buffer,SD_SECTOR_SIZE, &amp;temp, 0)
  </code></pre>
  
  <p>I get an Access denied (error #5)</p>
  
  <p>The string on CreateFile() is \.\g: as the g letter correspond to the SD card on my machine. All that works ok and as I said before it woks on XP. I also tried using: DeviceIoControl with FSCTL_LOCK_VOLUME but that gives a mem fault error.</p>
  
  <p>Hope this helps to understand and thanks for any help</p>