title: Access network share with PHP5.2 + IIS7.5
body: <p>I'm using php 5.2 with IIS7.5.</p>
  
  <p>I have a network share on a NAS that is username and password protected. I cannot disable or change authentication info on the NAS. I need to be able to access that network share via php.</p>
  
  <p>I've done the following:</p>
  
  <p>Created new user in windows whose username and password matches those on the NAS.
  Created IIS application pool that uses this same auth info.
  Created a web.config file inside of the php app directory with an impersonation turned on, using the same auth info.</p>
  
  <p>identity impersonate="true" password="ThePass" userName="TheUser" /></p>
  
  <p>Turned on ASP.NET impersonation in the application authentication in IIS.</p>
  
  <p>None of this seemed to work with this simple line of code in php:</p>
  
  <p>$dir = opendir("\\someservername\somesharename");
  Warning: opendir(\someservername\somesharename) [function.opendir]: failed to open dir: No error in C:\websites\site\forum\testing.php on line 7</p>
  
  <p>So, I decided to test the configuration with ASP.NET.</p>
  
  <p>string[] diretories = System.IO.Directory.GetDirectories("\\someservername\somesharename");
  The asp.net test worked perfectly.</p>
  
  <p>Going further down the rabbit hole, I ran phpinfo() and checked the username info in it. Down in the "Environment" section of phpinfo, I found the "USERNAME" item. Its value was "TheUser," as was what I expected.</p>
  
  <p>Everything points to the system being configured correctly until I tried:</p>
  
  <p>echo get_current_user();
  Which returned, "IUSR." That surely isn't what I expected.</p>
  
  <p>So, how in the world do I get php + IIS7.5 to read from a foreign network share?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks to a few of the answers, I've added </p>
  
  <pre><code>$result = shell_exec("net use o: \\\\pathToServer\\27301  /persistent:yes 2&gt;&amp;1");
  </code></pre>
  
  <p>Which returns a success.  I'm still getting the error on opendir.  I tried another test and used is_dir.  This returned false on my newly created mapped drive.</p>
  
  <pre><code>var_dump(is_dir("o:\\"));
  
  // Prints: bool(false) 
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I ran the script from the command line when logged in as the user that created.  The scripts executes correctly.  Could this take us back to get_current_user() which returns IUSR?  I tryied getmypid() which returned a process ID.  I cross referred that process id with the task manager and found that it was for php-cgi.exe, running under the custom user account that I made.</p>