PHP exec() command not working
<p>After hours and hours of trying and searching for an answer i coudn't get it working.</p>

<p><b>Hosting details:</b></p>

<p>Windows Server 2012 R2</p>

<p>Plesk 12</p>

<p>IIS 8.5</p>

<h2>The problem</h2>

<p>My problem is:
I want to execute this command in PHP. The command is necessary to reload the configs for filezilla, after creating a new user with an PHP script.</p>

<pre><code>C:\Program Files (x86)\FileZilla Server\FileZilla Server.exe /reload-config
</code></pre>

<p>It does work when i try it directly in CMD.
But in PHP if doens't somehow work. I tried so many things, that im going to try to give you all the manners i tried.</p>

<p>I tried to do this at the following ways:</p>

<h2>Trial 1</h2>

<pre><code>$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; 
exec( $command, $output, $return); 

print_r($output);
echo '&lt;br/&gt;' .$return;
</code></pre>

<p>Output:</p>

<pre><code>Array ( ) 
0
</code></pre>

<h2>Trial 2</h2>

<pre><code>$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; 
system( $command, $output); 

print_r($output);
</code></pre>

<p>Output: <code>0</code></p>

<h2>Trial 3</h2>

<pre><code>$command = 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; 
exec( $command, $output, $return); 

print_r($output);
echo '&lt;br/&gt;' .$return;
</code></pre>

<p>Output: <code>0</code></p>

<h2>Trial 4 (The only one that returns an error!)</h2>

<pre><code>exec( 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /stop 2&gt;&amp;1', $output); 
print_r($output);
</code></pre>

<p>Output:</p>

<pre><code>Array ( [0] =&gt; Toegang geweigerd. )
</code></pre>

<p>In english:</p>

<pre><code>Array ( [0] =&gt; Access denied. )
</code></pre>

<h1>Privileges:</h1>

<p>In allmost all awnsers found they talked about privileges. I did following privileges:</p>

<p>Gave all web users and IUSR privileges to CMD.exe and FileZilla Server.exe,
and tried to set the IIS authentication from anonymous to an Administrator account</p>

<p>Somebody said to try this:</p>

<pre><code>echo '&lt;pre&gt;';
    system('set', $retval);
echo ' &lt;/pre&gt;'; 
</code></pre>

<p>If i do that my output is: <a href="http://pastebin.com/SjzeQpJ0" rel="nofollow">http://pastebin.com/SjzeQpJ0</a></p>

<p>If you guys want anymore details just ask. I hope you guys can figure it out for me. I tried to be as clear as possible. Thanks.</p>

<p><h1>Finaly found the solution!!</h1><hr/>
If you encounter the same problem as i did, and you dont know how to fix this, follow this steps.</p>

<ol>
<li>Login to the Remote of your server (if you have access to it) Open</li>
<li>Open the IIS manager</li>
<li>Select -> Application Pools node underneath the machine node (left panel)</li>
<li>Right click on the desired domainname -> Advanced settings</li>
<li>Scroll to Process Model -> Id</li>
<li>Click on the 3 dots</li>
<li>Check the Custom Account radio button</li>
<li>Fill in an existing administration account which has access to the
remote desktop and of course its password</li>
<li>Press OK</li>
<li>Now go to the .exe or whatever file you want to access throught the
 exec command and</li>
<li>Right click on the file and select properties</li>
<li>Go to the security tab</li>
<li>Select Edit</li>
<li>Now grand full rights to the account you selected before. If its
 not listed than add it manualy by clicking on Add</li>
</ol>

<p><b>If you have done all of this, it now should work.</b></p>