Is it possible to start and stop a service in local computer with php?

if it is how?

    yes...

    try something like

    exec("NET [START|STOP] 'IIS ADMIN'");
    

    common services

    NET STOP "Error Reporting Service"
    NET STOP "FTP Publishing Service"
    SET STOP "IIS Admin"
    NET STOP "Messenger"

    NET START "Error Reporting Service"
    NET START "FTP Publishing Service"
    SET START "IIS Admin"
    NET START "Messenger"

    Consider invoking a batch file instead to make it simpler and be able to start/stop multiple services at one time

      9 days later

      I can get commands to work using:
      echo exec("help");

      However anytime I try to do a net start or stop the bowser just times out? Any ideas? on how/why the net start/stop commands won't work?
      echo exec("NET STOP 'Messenger'");

      I am using IIS 5.0 and Windows 2000 server with php 4.3.8

      Thank You,
      Chris Wheat

        permissions most likely...asin the user running the inside the web service (nobody) will not have the permissions to alter that object...try changing users or giving permissions to the noboy user

          Ok I found that if I go to start run cmd
          and from the wwwroot dir type
          net start Myservice
          it repeats the command in a nasty loop
          so I think the hang up is with the wwwroot.

          So I wrote a batch file in the wwwroot called test.bat
          it does :
          cd..
          net start myservice

          and if I run this from the start run it works fine.
          But from php I get:
          "Access is denied.
          Content-type: text/html
          X-Powered-By: PHP/4.3.8"

          I can not figure out were to tell windows that PHP has the ability to start/stop services?

          Thanks
          Chris

            Ok so I figured out that if I use php command line I can stop/start a service???

            so test.php (not in the wwwroot)
            looks like
            <?
            echo passthru("net start MyService");
            ?>

            so if I go to start, run, and type
            C:\PHP\php.exe C:\DIR\test.php

            it will start the service. So why would it work this way from php but not through the webserver?

            Thanks
            Chris Wheat

              a month later

              I am having the same problem essentially the IUSR????? account doesn't have permission to start/stop services If anyone figures out how to give permission to the IUSR????? account please post I know it is probably a security hole my preference is specific services but at this point all will work. 😕

                I don't know that it is a permission problem.

                Create a .bat file that does your netstop, or start, then save that .bat file in the wwwroot. Then from windows explorer (not php script) run the batch file you will see it opens up the command window and then will repeat the command indefinitely.

                So I believe that when php tries to do the command (from the wwwroot) it incounters the same thing an ongoing loop.

                Chris

                  I tried to recreate this, but couldn't. Although I change my directory from wwwroot to something else. I have finally gotten it to work, but it might have opened a security hole. reference this webpage http://support.microsoft.com/default.aspx?scid=kb;en-us;288129
                  to change the log on as service feature under Local Policies -> User Rights Assignment and under System Services -> choose the service you want to be able to modify. Although I still couldn't get this to work so I made a new account with group user (only) and change the setting in IIS manager properties -> Directory Security -> Edit Anonymous Access -> change from IUSR_????? to your new account.

                  Like I said It probably opened a security hole (not sure), but it works with this php.

                  <?
                  $command = "net start messenger 2>&1";

                  exec($command, $output);

                  foreach($output as $outputline){
                  echo("$outputline<br>");
                  }?>

                    What OS are you running? I use XP and I was doing my tests with right click on Command Prompt and choose run as then used my new account, which I initially had setup the same as IUSR_????.

                    Oh one more thing I tried removing the groups from IUSR_???? and just putting the User group and it was still failing. I think it is a M$ lockdown.

                      Windows 2000 server. But I never got it working in the wwwroot, luckely for me the task I had could be scheduled and ran from php's command line. (as long as the php script was outside of the wwwroot). I ran into this a few months ago and when I was searching I found a few dozen posts with people that had the same problems, but never could find a solution. One person was able to start and stop services by downgrading the IIS server (I think to version 5)?

                        With IIS you can go into properties and choose the "File Security" Tab. So instead of the whole website not Using IUSR_???? only the one page uses a different account.

                          Write a Reply...