home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 April / PCWorld_2004-04_cd.bin / software / temacd / remotany / RemotelyAnywhere.msi / Services.sma < prev    next >
Text File  |  2003-08-19  |  4KB  |  139 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //                                                                            //
  3. // RemotelyAnywhere Sample 'SMALL' Scripts                                    //
  4. //                                                                            //
  5. // RemotelyAnywhere provides a mechanism for scripting via a built-in         //
  6. // language. The language is called Small, and more information about         //
  7. // it can be found at http://compuphase.com/small.htm.                        //
  8. //                                                                            //
  9. // Before you use these sample scripts, you should tailor their               //
  10. // behavior to better suit your configuration and your needs.                 //
  11. //                                                                            //
  12. // This script will display all services and drivers on the computer. You can //
  13. // control them via the callback function.                                    //
  14. //                                                                            //
  15. // THIS SOFTWARE IS PROVIDED BY 3AM LABS LTD ``AS IS'' AND                    //
  16. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE      //
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE //
  18. // ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE    //
  19. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL //
  20. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS    //
  21. // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)      //
  22. // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT //
  23. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY  //
  24. // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF     //
  25. // SUCH DAMAGE.                                                               //
  26. //                                                                            //
  27. ////////////////////////////////////////////////////////////////////////////////
  28.  
  29. #include <ra>
  30.  
  31. public main()
  32. {
  33.     new name[64], display[64], bin[64], type, status, startup;
  34.     new startstr[5][]={"Boot", "System", "Auto", "User", "Disabled"};
  35.  
  36.     htmlBeginOutput("Services/drivers");
  37.  
  38.     //
  39.     // Check whether service enumeration was successful
  40.     //
  41.  
  42.     if (raEnumServices()) {
  43.         htmlBeginTable("Name", "Display name", "Binary", "Type", "Status", "Startup");
  44.  
  45.         //
  46.         // Loop through each service
  47.         //
  48.  
  49.         new num=raGetServiceNum();
  50.         for (new i=0; i<num; i++) {
  51.             htmlBeginTableRow();
  52.  
  53.             raGetService(i, name, display, bin, type, status, startup);
  54.  
  55.             //
  56.             // Show service name as a callback
  57.             // pass the "tokill" or "tostart" parameter with the
  58.             // service name depending on its status
  59.             //
  60.  
  61.             htmlBeginTableCell();
  62.             htmlCBLink(name, "callb", status==SERVICE_RUNNING ? "tokill" : "tostart", name);
  63.             htmlEndTableCell();
  64.  
  65.             htmlTableCell(display);
  66.             htmlTableCell(bin);
  67.  
  68.             //
  69.             // Check if it's a driver or service
  70.             //
  71.  
  72.             if (type<SERVICE_WIN32_OWN_PROCESS) {
  73.                 htmlTableCell("driver");
  74.             } else {
  75.                 htmlTableCell("service");
  76.             }
  77.  
  78.             if (status==SERVICE_RUNNING)
  79.                 htmlTableCell("running");
  80.             else
  81.                 htmlTableCell("not running");
  82.  
  83.             htmlTableCell(startstr[startup]);
  84.  
  85.             htmlEndTableRow();
  86.         }
  87.  
  88.         htmlEndTable();
  89.         raEnumServicesClose();
  90.     } else {
  91.         htmlWrite("Failed to show service/driver list<BR>");
  92.     }
  93.  
  94.     htmlButtonBack();
  95.  
  96.     htmlEndOutput();
  97. }
  98.  
  99. //
  100. // Callback function to start/stop a service
  101. //
  102.  
  103. public callb()
  104. {
  105.     htmlBeginOutput("Service management");
  106.  
  107.     new buf[256], buf2[256];
  108.  
  109.     //
  110.     // Check which parameter was filled
  111.     //
  112.  
  113.     if (htmlGetParam("tokill", buf)) {
  114.         if (raStopService(buf))
  115.             sprintf(buf2, "Service \"%s\" stopping...<BR><BR>", buf);
  116.         else
  117.             sprintf(buf2, "Can't stop service \"%s\"<BR><BR>", buf);
  118.     } else if (htmlGetParam("tostart", buf)) {
  119.         if (raStartService(buf))
  120.             sprintf(buf2, "Service \"%s\" starting...<BR><BR>", buf);
  121.         else
  122.             sprintf(buf2, "Can't start service \"%s\"<BR><BR>", buf);
  123.     }
  124.  
  125.     //
  126.     // Show output
  127.     //
  128.  
  129.     htmlBeginForm();
  130.     htmlBeginDialog("Result");
  131.     htmlWrite(buf2);
  132.     htmlButton("Back", "main");
  133.     htmlWrite("<BR><BR>");
  134.     htmlEndDialog();
  135.     htmlEndForm();
  136.  
  137.     htmlEndOutput();
  138. }
  139.