title: Make a directory/usb drive Read Only in windows c/c++
body: <p>I am using <strong><code>CreateFile</code></strong> to make a directory READ ONLY using <strong><code>FILE_ATTRIBUTE_READONLY</code></strong> as dwFlagsAndAttributes. </p>
  
  <p>However this blocks the access to the drive completely. I can't traverse the directory or see any files inside it. </p>
  
  <p>It shows <strong>Access is denied</strong>.</p>
  
  <p>My code :</p>
  
  <pre><code>LPWSTR wszPath = L"\\\\.\\F:";      // path to the drive
  HANDLE hDevice = INVALID_HANDLE_VALUE;  // handle to the drive
  hDevice = CreateFile(wszPath,          // drive to open
              (GENERIC_READ|GENERIC_WRITE),    
              FILE_SHARE_READ,  // share mode
              NULL,             // default security attributes
              OPEN_EXISTING,    
              FILE_ATTRIBUTE_READONLY,       // file attributes
              NULL); 
  if (hDevice == INVALID_HANDLE_VALUE)    // cannot open the drive
      {
          wprintf(L" hDevice INVALID_HANDLE_VALUE. Error %ld.\n", GetLastError());
          CloseHandle(hDevice);
          return (FALSE);
      }
        wprintf(L"Successfully opened");
  </code></pre>
  
  <p><strong>Error message pic</strong> : 
  <img src="https://i.stack.imgur.com/iE8Aw.png" alt="pic"></p>
  
  <p>As I am passing file attributes as <strong>FILE_ATTRIBUTE_READONLY</strong> so it should be ONLY read only,why It can't let access to the files.</p>
  
  <p>Language : c++</p>
  
  <p>platform : windows</p>
  
  <p>Any idea?</p>
  
  <p>Thanks in Advance.</p>