title: PHP Not executing .bat file in windows
body: <p>I am trying to execute a batch file using PHP on Windows Server 2008.</p>
  
  <p>The file is called <code>NEWDNS.bat</code> and its purpose is to write a new entry into a DNS zone file stored in <code>c:\windows\system32\dns</code>. The zone file is named <code>motlocal.co.uk</code>.</p>
  
  <p>Here are the contents of <code>newdns.bat</code></p>
  
  <hr>
  
  <pre class="lang-bat prettyprint-override"><code>@echo off
  cd windows\system32\dns\
  dnscmd dsvr012345 /recordadd motlocal.co.uk mynewsubdomain A 88.208.200.221
  dnscmd dsvr012345 /ZoneReload motlocal.co.uk
  </code></pre>
  
  <hr>
  
  <p>newdns.bat is stored in the same directory on the server as the PHP page that calls it:-</p>
  
  <p>Here's the contents of the page that calls newdns.bat (the php page is called dnscreator.php)</p>
  
  <hr>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  if(isset($_POST['submit']))
  {
      echo exec("cmd.exe /c newdns.bat");
      echo "Done!";
  } else {
  ?&gt;
      &lt;form action="" method="post"&gt;
      &lt;input type="submit" name="submit" value="DO IT!"&gt;
      &lt;/form&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>When I double click on the batch file from a windows folder - it runs and it executes its commands perfectly and creates the new subdomain in the dns zone file.</p>
  
  <p>However - no matter how I try (and I have been on this for 2 days now) it it will NOT execut when I run dnscreator.php.</p>
  
  <p>The form executes and displays the message "Done!" but the commands in the newdns.bat have not been carried out. I know the batch file works because as I said - I can run it from a windows folder (Double Click) and it does what its supposed to do.</p>
  
  <p>PHP Safe mode is OFF, just in case you were wondering and I have tried moving the batch file into c:\windows\system32 and this didn't work either.</p>
  
  <p>Any help / advice / pointers you can give is greatly appreciated - I am at my wits end! Many Thanks.</p>