1

The problem is simple. Running a php file in browser vs command line produces very different results and I can't for the life of me figure out why. Any php/psexec experts out there run into this before?

<?php

echo '<pre>';
$output = shell_exec("psexec -accepteula \\\mypcname -u mypcname\\accountname -p xxxxxxx ipconfig /all 2>&1");
var_dump($output);
echo '</pre>';

Produces this output in a browser window...

string(350) "
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com


Windows IP Configuration

Connecting to admin-pc...


Starting PSEXESVC service on admin-pc...


Connecting with PsExec service on admin-pc...


Starting ipconfig on admin-pc...


ipconfig exited on admin-pc with error code 0.  

Instead of this, which is the output I get when running the same php file via command line.

C:\MAMP\bin\php\php5.5.12>php-cgi c:\mamp\htdocs\go.php
X-Powered-By: PHP/5.5.12
Content-type: text/html

hi<pre>string(5113) "
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com


Windows IP Configuration

   Host Name . . . . . . . . . . . . : mypcname
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : home

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Intel(R) 82567LM-2 Gigabit Network Connec
   tion
   Physical Address. . . . . . . . . : xx-xx-xx-xx-xx-xx
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Thursday, October 09, 2014 4:36:43 PM
   Lease Expires . . . . . . . . . . : Tuesday, October 14, 2014 4:16:04 PM
   Default Gateway . . . . . . . . . : 192.168.1.1
   DHCP Server . . . . . . . . . . . : 192.168.1.1

   DNS Servers . . . . . . . . . . . : 8.8.8.8
                                       8.8.4.4
   NetBIOS over Tcpip. . . . . . . . : Enabled
"
</pre>
C:\MAMP\bin\php\php5.5.12>
Skej
  • 172
  • 1
  • 14
  • I think it's because when you're running via command line, you're not elevated. However, your webserver is an administrator. Try creating a new shortcut to cmd.exe, and running that as an administrator to run your PHP. – Dave Chen Oct 14 '14 at 02:00
  • Hmm was a good suggestion but I get the same results =\ – Skej Oct 14 '14 at 02:50
  • Can you try the same thing but using `php.exe` instead of `php-cgi.exe`? – Dave Chen Oct 14 '14 at 02:52
  • Some more info to digest, I know that psexec is executing the command properly on the remote pc because I can tweak the line in php and launch notepad, calculator etc on the remote pc It's just the stdout or stderr that's not reaching the browser. – Skej Oct 14 '14 at 02:54
  • Same results with php.exe – Skej Oct 14 '14 at 02:56

0 Answers0