title: Open Directory Using CreateFile
body: <p>I am trying to utilize the CreateFile function to access directory information. I am recieving a win32 error code of 5 however, which means Access Denied. Please advise.</p>
  
  <pre><code>CreateFile(path, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero);
  </code></pre>
  
  <p>This is the call being made, and as noted in the documentation the 'FILE_FLAG_BACKUP_SEMANTICS' is being used. The DLL import seems to be working fine and looks like the following:</p>
  
  <pre><code>[DllImport("kernel32.dll", SetLastError = true)]
  public static extern IntPtr CreateFile(string filename,
                                      uint desiredAccess,
                                      uint sharedMode,
                                      IntPtr securityAttributes,
                                      uint creationDisposition,
                                      uint flagsAndAttributes,
                                      IntPtr templateFile);
  </code></pre>
  
  <p>Update: I need to obtain the handle to a directory so i can use GetFileInformationByHandle() and extract the unique id. This method currently works with files, it is not working with directories currently.</p>
  
  <p>Update: The X for this question is i need a unique identifier of a directory that is something other than its absolute path. It needs to remain the same even if directory is moved or renamed. .NET does not provide any unique identifiers as just mentioned, it can only be accomplished by using win32 </p>