title: Read/Write files with UNC path - in c++
body: <p>I wrote a bit of code that reads/writes stuff...</p>
  
  <p>I would like to add an option to read/write to UNC paths.</p>
  
  <p>A bit of code:</p>
  
  <pre><code>if (boost::filesystem::exists (file_name))
  {
    std::ifstream in_file(file_name.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
    if(in_file.is_open())
    {
      in_file.read(...);
      in_file.close();
    }
  }
  </code></pre>
  
  <p>If the network share I am trying to use has been used before, this works.</p>
  
  <p>But if I try with a share from a computer that I have not seen before, I get error:</p>
  
  <pre><code>boost::filesystem::status: Logon failure: unknown user name or bad password: "\\xx\test.txt"
  </code></pre>
  
  <p>I'd like to avoid the exception, check the boost::filesystem::status for... what ? Looking in documentation, it seems that it can tell me if I have a regular file, or a directory... but <strong>how can I check if I have the correct permissions</strong> ?</p>
  
  <p>Is there a way to actually send in the user name and password ?</p>
  
  <p>Edit: found that I could call</p>
  
  <pre><code>Net Use \\yourUNC\path /user:uname password
  </code></pre>
  
  <p>also: 
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa375187(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/aa375187(v=vs.85).aspx</a></p>
  
  <p>I think either of these would make the code platform dependent ?</p>
  
  <p>Also, if I do log in every time - in a sequence of 10000 calls, this would result in serious slowing down ?</p>
  
  <p>Is there any way to check if the user is logged in ?</p>
  
  <p>Note: I am using boost 1.47 - mostly windows but I'd like to be platform independent.</p>
  
  <p>Thank you.</p>