title: Can I deny FILE_SHARE_WRITE to others without granting myself GENERIC_WRITE?
body: <p>I was writing a custom write-locking class when I noticed it. My class has no reason to actually write to the file, only to deny others the ability to write, so naturally I tried this:</p>
  
  <pre><code>lockHandle = CreateFileW(fileName, 0, FILE_SHARE_READ, 0, OPEN_EXISTING,  FILE_ATTRIBUTE_NORMAL, 0);
  </code></pre>
  
  <p>As you can see, I set <code>dwDesiredAccess=0</code> and <code>dwShareMode=FILE_SHARE_READ</code>. But other processes can still write to the file. It took me some time to realize I need to set <code>dwDesiredAccess=GENERIC_WRITE</code>, or else my <code>dwShareMode</code> has no effect.</p>
  
  <p>It seems I can deny others permissions only if I grant them to myself as well. Is that correct? If so, why is that?</p>