home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / pm-app.zip / stopapp.cmd < prev   
OS/2 REXX Batch file  |  1997-04-29  |  5KB  |  156 lines

  1. /* STOPAPP.CMD 
  2.  
  3.       REXX Program to stop KAT and start STARTAPP.CMD at a particular time.
  4.       This program can be modified to control any OS/2 PM application.
  5.       This program requires REXXUTIL.DLL and APMT 3.5, (Automated PM Tester/Driver version 3.5), a REXX add-on.
  6.       Press Q or q to stop this program.
  7.  
  8.       Released to Public Domain - feel free to use and modify this code to your content.
  9.  
  10.       Author: A. Schwarz 
  11.       Date: 4-28-97 
  12. */
  13.  
  14.  
  15. Trace off
  16. call APMT_INIT
  17.  
  18. IF LoadRexxUtil() THEN
  19.   EXIT
  20.  
  21. StopTime = '10:00'     /* This is the stop time of the application. Use military time and fill */
  22.                        /* in a zero for single digit hour, i.e 1:00am = 01:00 */
  23.  
  24. AppName = 'Kat'        /* This is the application to be stopped. This name must match exactly */
  25.                        /* what appears in the window title of the application, upper/lowercase sensitive! */
  26.  
  27. SAY 'Scheduler Program to stop ' || AppName
  28. SAY 'Stop Time: ' || StopTime
  29. SAY ''
  30. SAY 'Press Q to quit program.'
  31. SAY ''
  32.  
  33. OldTime = LEFT(TIME(), 5)
  34. SAY "Current Time: " || OldTime
  35.  
  36. Loop:
  37.  
  38. CurrTime = LEFT(TIME(), 5)
  39. IF CurrTime <> OldTime THEN
  40.    DO
  41.      SAY "Current Time: " || CurrTime   /* display current time once every minute */
  42.      OldTime = CurrTime
  43.    END
  44.  
  45. IF StopTime = CurrTime THEN
  46.    DO
  47.      CloseTry = 0
  48.      rc = SELECT_WINDOW(AppName,"10")    /* this checks the window title of the application to be stopped */
  49.      if rc > 0 then
  50.        DO
  51.          say AppName || " not found..."
  52.        END
  53.      else
  54.  
  55. TryClose:
  56.        DO
  57.           say "Stopping " || AppName || "..."
  58.           /* All done; If the program was started, terminate it */
  59.           rc = SELECT_WINDOW(AppName)
  60.           SAY 'Select to close ' || AppName || ', rc = ' || rc
  61.           rc = SYSMENU_SELECT("Close")
  62.  
  63.           SAY 'Waiting 30 seconds. Press Q to quit...'
  64.           count = 0
  65.           DO WHILE count < 30
  66.             CALL SysSleep 1           /* wait 30 seconds for program to close, then check again if it is closed */
  67.             count = count + 1
  68.             IF CHARS() <> 0 THEN      /* check if there is a keyboard entry and get key if any */
  69.               DO
  70.                 key = SysGetKey('NOECHO')
  71.                 IF key = 'q' | key = 'Q' THEN
  72.                 EXIT
  73.               END
  74.           END
  75.  
  76.           rc = SELECT_WINDOW(AppName,"10")   /* make certain application is closed, try no more than 3 times if it does not close */
  77.           if rc > 0 | CloseTry > 3 then
  78.             DO  
  79.               'start STARTAPP.CMD'    /* KAT has been terminated, start STARTAPP.CMD and close this program */
  80.               'exit'
  81.             END
  82.           else
  83.             DO
  84.                 /* AppName is still open, attempting to close it... */
  85.                CloseTry = CloseTry + 1
  86.                Signal TryClose
  87.             END
  88.  
  89.         END
  90.  
  91.      /******************************************************************/
  92.      /* Part 3: common suffix for all APMT programs                    */
  93.      /******************************************************************/
  94.      APMT_CLOSE:
  95.      rc = END_SESSION();
  96.      /******************************************************************/
  97.      errorexit:
  98.      exit
  99.  
  100.    END
  101.  
  102. ELSE
  103.  
  104.    count = 0
  105.    DO WHILE count < 10
  106.       CALL SysSleep 1           /* wait 10 seconds */
  107.       count = count + 1
  108.  
  109.       IF CHARS() <> 0 THEN   /* check if there is a keyboard entry and get key if any */
  110.         DO
  111.           key = SysGetKey('NOECHO')
  112.           IF key = 'q' | key = 'Q' THEN
  113.              EXIT
  114.         END
  115.    END
  116.  
  117. SIGNAL Loop
  118.  
  119. EXIT
  120.  
  121. /* Load the RexxUtil library */
  122. LoadRexxUtil:
  123.  IF RxFuncQuery('SysLoadFuncs') THEN
  124.    DO
  125.     IF RxFuncAdd('SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs') THEN
  126.        DO
  127.          SAY "Error: Couldn't load RexxUtil library."
  128.          RETURN 1
  129.        END
  130.        CALL SysLoadFuncs
  131.    END
  132. RETURN 0
  133.  
  134. DropFUNC:
  135.  call APMTDropFuncs;
  136.  call rxfuncdrop(APMTDropFuncs)
  137. return
  138.  
  139. APMT_INIT:
  140. call rxfuncadd  'APMTLoadFuncs',  'apmtext', 'APMTLoadFuncs'  /* entry points from the DLL    */
  141. call APMTLoadFuncs;
  142. rc = INIT_SESSION();
  143. if rc \= 0
  144.    then do
  145.      say apmtmsg
  146.      exit
  147.    end
  148.  
  149. signal on error name  APMT_CLOSE
  150. if apmtver.client \= apmtver.server then
  151.    say 'WARNING: Version mismatch. Client ='apmtver.client 'Server ='apmtver.server
  152.    else say 'Running APMT version 'apmtver.client
  153. signal on halt name APMT_CLOSE
  154. return
  155.  
  156.