Launching a program with exec & pstools/psexec.exe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vol30w60

    #1

    Launching a program with exec & pstools/psexec.exe

    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:


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

    <?php

    exec('C:\PsTool s\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\psex ec.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) "Sysinterna ls - www.sysinternal s.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

    #2
    Re: Launching a program with exec &amp; pstools/psexec.exe

    vol30w60 wrote:
    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:

    >
    To simplify things, I am trying to launch notepad with the following
    line of code:
    >
    <?php
    >
    exec('C:\PsTool s\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\psex ec.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) "Sysinterna ls - www.sysinternal s.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.

    Comment

    • Toby A Inkster

      #3
      Re: Launching a program with exec &amp; pstools/psexec.exe

      Schraalhans Keukenmeester wrote:
      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!

      Comment

      • vol30w60

        #4
        Re: Launching a program with exec &amp; pstools/psexec.exe

        Schraalhans Keukenmeester wrote:
        vol30w60 wrote:
        >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:\PsToo ls\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\pse xec.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) "Sysinterna ls - www.sysinternal s.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.

        Comment

        • vol30w60

          #5
          Re: Launching a program with exec &amp; pstools/psexec.exe

          vol30w60 wrote:
          Schraalhans Keukenmeester wrote:
          >vol30w60 wrote:
          >>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:\PsTo ols\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\ps exec.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) "Sysinterna ls - www.sysinternal s.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.

          Comment

          Working...