home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 April / PCWorld_2004-04_cd.bin / software / temacd / remotany / RemotelyAnywhere.msi / WatchProcess.sma < prev    next >
Text File  |  2003-08-19  |  4KB  |  141 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 check if Notepad is running. It can be run interactively  //
  13. // (ie. from the Scripts menu, or can be called from a Monitoring Script.     //
  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.         //
  34.         // Do we have HTML output?
  35.         //
  36.     new outp;
  37.  
  38.         //
  39.         // Was the process found?
  40.         //
  41.         new found = false;
  42.  
  43.         //
  44.         // Process Enumeration Variables
  45.         //
  46.     new pid, name[64], cpu, mem;
  47.  
  48.         //
  49.         // The process we are watching
  50.         //
  51.     new processname[] = "c:\\windows\\system32\\notepad.exe";
  52.  
  53.         //
  54.         // Prepare title for HTML page
  55.         //
  56.     sprintf(name, "Watch for process %s", processname); 
  57.  
  58.         //
  59.         // Attempt HTML output (will fail if run from the monitoring script)
  60.         //
  61.     outp = htmlBeginOutput(name); 
  62.  
  63.         //        
  64.         // Enumerate processes
  65.         //
  66.     if (raEnumProcs()) { 
  67.  
  68.                 //
  69.                 // How many are there?
  70.                 //
  71.         new num=raGetProcessNum();
  72.  
  73.                 //
  74.                 // Loop through each process
  75.                 //
  76.         for (new i=0; i<num; i++) {
  77.  
  78.             new tmp[20];
  79.  
  80.                     //
  81.                     // Get process properties
  82.                     //
  83.             raGetProcess(i, pid, name, cpu, mem);
  84.  
  85.                     //
  86.                     // Compare names
  87.                     //
  88.             if (!stricmp(processname, name)) {
  89.             
  90.                         //
  91.                         // Found it!
  92.                         //
  93.                         
  94.                 if (outp) {
  95.                 
  96.                             //
  97.                             // Report if running in interactive mode
  98.                             //
  99.                     sprintf(tmp, "%d", pid);
  100.                     htmlWrite(processname);
  101.                     htmlWrite(" is running with process ID ");
  102.                     htmlWrite(tmp);
  103.                     htmlWrite(".<BR><BR>");
  104.                 }
  105.                 found = true;
  106.                 break;
  107.             }
  108.         }
  109.  
  110.             //
  111.             // End process enumeration
  112.             //
  113.             
  114.         raEnumProcsClose();
  115.         
  116.     }
  117.  
  118.     if (outp) {
  119.     
  120.         if (!found)
  121.         {
  122.             htmlWrite("Could not find process ");
  123.             htmlWrite(processname);
  124.             htmlWrite(".<BR><BR>");
  125.         }
  126.         
  127.         htmlBeginForm();
  128.         htmlButtonBack("Back", false);
  129.         htmlEndForm();
  130.     
  131.         htmlEndOutput();
  132.     }
  133.     
  134.     //
  135.     // Return zero if found, non-zero if not found
  136.     //
  137.     
  138.     return !found;
  139. }
  140.  
  141.