Connecting Tech Pros Worldwide Forums | Help | Site Map

Launching a program with exec & pstools/psexec.exe

vol30w60
Guest
 
Posts: n/a
#1: Apr 9 '07
Hi folks,

I am trying to launch a program with PHP code. I am running Apache on
Windows XP SP2.

I am using the method noted here:
http://us2.php.net/manual/en/function.exec.php#59428

To simplify things, I am trying to launch notepad with the following
line of code:

<?php

exec('C:\PsTools\psexec.exe -d -s notepad.exe 2>&1', $output);

?>

I can see psexec running in the Task Manager, but it does not launch
notepad and does not return control to PHP. If I manually quit psexec
from the Task Manager, PHP will resume executing the script.

Running this from the command line works fine:
C:\PsTools\psexec.exe -d -s notepad.exe 2>&1

If I force quit psexec and do a var_dump() on $output, I see:

array(5) { [0]=string(0) "" [1]=string(41) "PsExec v1.82 - Execute
processes remotely" [2]=string(40) "Copyright (C) 2001-2007 Mark
Russinovich" [3]=string(35) "Sysinternals - www.sysinternals.com"
[4]=string(0) "" }

Note that there is no error message, but the expected output should have
a sixth line something like this:
notepad.exe started on HAL with process ID 4668.

Any ideas on how I can get this to work?



Schraalhans Keukenmeester
Guest
 
Posts: n/a
#2: Apr 10 '07

re: Launching a program with exec & pstools/psexec.exe


vol30w60 wrote:
Quote:
Hi folks,
>
I am trying to launch a program with PHP code. I am running Apache on
Windows XP SP2.
>
I am using the method noted here:
http://us2.php.net/manual/en/function.exec.php#59428
>
To simplify things, I am trying to launch notepad with the following
line of code:
>
<?php
>
exec('C:\PsTools\psexec.exe -d -s notepad.exe 2>&1', $output);
>
?>
>
I can see psexec running in the Task Manager, but it does not launch
notepad and does not return control to PHP. If I manually quit psexec
from the Task Manager, PHP will resume executing the script.
>
Running this from the command line works fine:
C:\PsTools\psexec.exe -d -s notepad.exe 2>&1
>
If I force quit psexec and do a var_dump() on $output, I see:
>
array(5) { [0]=string(0) "" [1]=string(41) "PsExec v1.82 - Execute
processes remotely" [2]=string(40) "Copyright (C) 2001-2007 Mark
Russinovich" [3]=string(35) "Sysinternals - www.sysinternals.com"
[4]=string(0) "" }
>
Note that there is no error message, but the expected output should have
a sixth line something like this:
notepad.exe started on HAL with process ID 4668.
>
Any ideas on how I can get this to work?
>
>
Which user shows in TaskManager running psexec (and Notepad?) when run
from PHP vs. from commandline? I don't know the program psexec btw. Is
that a must-use for exec-ing stuff in windows from apache?

Sh.
Toby A Inkster
Guest
 
Posts: n/a
#3: Apr 10 '07

re: Launching a program with exec & pstools/psexec.exe


Schraalhans Keukenmeester wrote:
Quote:
I don't know the program psexec btw. Is that a must-use for exec-ing
stuff in windows from apache?
It's part of the "pstools" bundle which has a bunch of handy command-line
programs for Windows. It's useful for launching programs on remote
machines, shutting down machines remotely, getting lists of logged in
users, current processes, etc.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
vol30w60
Guest
 
Posts: n/a
#4: Apr 10 '07

re: Launching a program with exec & pstools/psexec.exe


Schraalhans Keukenmeester wrote:
Quote:
vol30w60 wrote:
Quote:
>Hi folks,
>>
>I am trying to launch a program with PHP code. I am running Apache on
>Windows XP SP2.
>>
>I am using the method noted here:
>http://us2.php.net/manual/en/function.exec.php#59428
>>
>To simplify things, I am trying to launch notepad with the following
>line of code:
>>
><?php
>>
>exec('C:\PsTools\psexec.exe -d -s notepad.exe 2>&1', $output);
>>
>?>
>>
>I can see psexec running in the Task Manager, but it does not launch
>notepad and does not return control to PHP. If I manually quit psexec
>from the Task Manager, PHP will resume executing the script.
>>
>Running this from the command line works fine:
>C:\PsTools\psexec.exe -d -s notepad.exe 2>&1
>>
>If I force quit psexec and do a var_dump() on $output, I see:
>>
>array(5) { [0]=string(0) "" [1]=string(41) "PsExec v1.82 - Execute
>processes remotely" [2]=string(40) "Copyright (C) 2001-2007 Mark
>Russinovich" [3]=string(35) "Sysinternals - www.sysinternals.com"
>[4]=string(0) "" }
>>
>Note that there is no error message, but the expected output should have
>a sixth line something like this:
>notepad.exe started on HAL with process ID 4668.
>>
>Any ideas on how I can get this to work?
>>
>>
Which user shows in TaskManager running psexec (and Notepad?) when run
from PHP vs. from commandline? I don't know the program psexec btw. Is
that a must-use for exec-ing stuff in windows from apache?
>
Sh.
Thanks for the reply.

psexec.exe runs under my user account from the command line. I can
control which user runs notepad.exe from the command line using the -s
flag for System, or I can specify a different user with the -u and -p flags.

psexec.exe runs as System from PHP.

It makes me wonder if this is related to access privileges, but I don't
know what the correct settings are. Do all the executables have to be in
the same directory? Do I have to configure PHP with certain access
privileges? I'm not very skilled with these settings on Windows.

vol30w60
Guest
 
Posts: n/a
#5: Apr 10 '07

re: Launching a program with exec & pstools/psexec.exe


vol30w60 wrote:
Quote:
Schraalhans Keukenmeester wrote:
Quote:
>vol30w60 wrote:
Quote:
>>Hi folks,
>>>
>>I am trying to launch a program with PHP code. I am running Apache on
>>Windows XP SP2.
>>>
>>I am using the method noted here:
>>http://us2.php.net/manual/en/function.exec.php#59428
>>>
>>To simplify things, I am trying to launch notepad with the following
>>line of code:
>>>
>><?php
>>>
>>exec('C:\PsTools\psexec.exe -d -s notepad.exe 2>&1', $output);
>>>
>>?>
>>>
>>I can see psexec running in the Task Manager, but it does not launch
>>notepad and does not return control to PHP. If I manually quit psexec
>>from the Task Manager, PHP will resume executing the script.
>>>
>>Running this from the command line works fine:
>>C:\PsTools\psexec.exe -d -s notepad.exe 2>&1
>>>
>>If I force quit psexec and do a var_dump() on $output, I see:
>>>
>>array(5) { [0]=string(0) "" [1]=string(41) "PsExec v1.82 - Execute
>>processes remotely" [2]=string(40) "Copyright (C) 2001-2007 Mark
>>Russinovich" [3]=string(35) "Sysinternals - www.sysinternals.com"
>>[4]=string(0) "" }
>>>
>>Note that there is no error message, but the expected output should have
>>a sixth line something like this:
>>notepad.exe started on HAL with process ID 4668.
>>>
>>Any ideas on how I can get this to work?
>>>
>>>
>Which user shows in TaskManager running psexec (and Notepad?) when run
>from PHP vs. from commandline? I don't know the program psexec btw. Is
>that a must-use for exec-ing stuff in windows from apache?
>>
>Sh.
>
Thanks for the reply.
>
psexec.exe runs under my user account from the command line. I can
control which user runs notepad.exe from the command line using the -s
flag for System, or I can specify a different user with the -u and -p
flags.
>
psexec.exe runs as System from PHP.
>
It makes me wonder if this is related to access privileges, but I don't
know what the correct settings are. Do all the executables have to be in
the same directory? Do I have to configure PHP with certain access
privileges? I'm not very skilled with these settings on Windows.
>
Success! -- and I cannot believe how ridiculous this was. Apparently,
psexec.exe will not run until you accept the EULA. To do that, you need
to add the flag -accepteula to your command string! I did not see this
mentioned anywhere in the documentation, but I found the solution on a
message board after much searching. Hope this helps someone else.
Closed Thread