Ver Mensaje Individual
  #2
Antiguo 5 de noviembre de 2024, 21:11
fastpho
El Foro es mi casa
Innovación: Por aportar innovaciones - Issue reason: SQLite + OO Cobol class Concurso: Primer puesto: Ganador/a del Primer puesto en un concurso - Issue reason: Acceso a datos Cobol vía web 
Última Actividad 21.08.2026 18:08
Posts Posts: 365
Likes enviados Enviados: 252
Likes recibidos Recibidos: 243

Hola @Joseg , si estas buscando saber si una appxxx.exe esta ejecutandose dos formas :
una con el control ocx ScriptControl
Código COBOL:
  1.  
  2.  ENVIRONMENT     DIVISION.
  3.  DATA            DIVISION.
  4.  WORKING-STORAGE SECTION.
  5.  01 scriptCode1   pic x(500).
  6.  PROCEDURE       DIVISION.
  7.               MOVE SPACES TO scriptCode1.
  8.               string    
  9.                    'Sub MYProgram() ' vbCRLF        
  10.                    ' Set objWMI = GetObject("winmgmts:\.
  11. ootcimv2")' vbCRLF
  12.                    ' Set colProcesses = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = ""ElsisGestion.exe"" ") ' vbCRLF
  13.                    ' If colProcesses.Count = 0 Then' vbCRLF
  14.                    '    MsgBox "El programa no se está ejecutando"' vbCRLF
  15.                    ' Else' vbCRLF
  16.                    '    MsgBox "El programa se está ejecutando"' vbCRLF
  17.                    ' End If'     vbCRLF
  18.                    'End Sub' vbCRLF                                        
  19.                    delimited by size into scriptCode1
  20.               end-string.
  21.  
  22.       INVOKE scriptControl1 "Reset".
  23.       INVOKE scriptControl1 "AddCode" USING scriptCode1.
  24.       INVOKE scriptControl1 "ExecuteStatement" USING "MYProgram".
  25.  
  26.      
  27.              

Otra forma es buscando la ventana del appxxx.exe con api de windows : GetTopWindow , GetWindow , GetWindowTextA
Código COBOL:
  1.  special-names.
  2.         symbolic constant
  3.             gw_hwndfirst    is 0
  4.             gw_hwndnext     is 2
  5.         .
  6.  data division.
  7.  working-storage section.
  8.  01 get-this-window-handle.
  9.         05  this-window-handle          pic s9(9)   comp-5  value 0.
  10.         05  filler                      pic x(12)           value spaces.
  11.        
  12.  01 title-bar-search-string         pic x(1025)         value spaces.
  13.  01 title-bar-index                 pic 9(9)    comp-5  value 0.
  14.  
  15.  01 child-window-handle             pic s9(9)   comp-5  value 0.
  16.  01 parent-window-handle            pic s9(9)   comp-5  value 0.
  17.  
  18.  01 length-of-title-bar-buffer      pic s9(9)   comp-5.
  19.  01 title-bar-buffer-max            pic s9(9)   comp-5.
  20.  01 title-bar-buffer                pic x(1025)         value spaces.              
  21.        
  22.  01 hwnd-type                       pic 9(9)    comp-5.
  23.            
  24.  01     null-value                      pic s9(9)   comp-5  value 0.
  25.  
  26.  linkage section.
  27.  01 title-bar-string                pic x(1024).
  28.  01 found-window-sw                 pic 9(4)    comp-5.
  29.  01 found-window-handle             pic s9(9)   comp-5.
  30.  01 return-value                    pic s9(9)   comp-5.
  31.    
  32.  procedure division using title-bar-string, found-window-sw, found-window-handle, return-value.
  33.         move 0 to return-value
  34.         move 0 to found-window-sw
  35.         move 0 to found-window-handle
  36.        
  37.         compute title-bar-buffer-max = function length(title-bar-buffer)
  38. *      
  39. * Let's make sure they passed the title bar string
  40. *
  41.         if title-bar-string not > " "
  42.             move 1 to return-value
  43.             exit program
  44.         end-if
  45. *
  46. * Let's get the handle of this window
  47. *
  48.         call "GetTopWindow" with STDCALL using
  49.             by value null-value
  50.             returning this-window-handle
  51. *
  52. * Now, let's find the length of the search string
  53. *
  54.         move title-bar-string to title-bar-search-string
  55.         perform varying title-bar-index from 1025 by -1
  56.                 until title-bar-search-string(title-bar-index:1) not = " "
  57.             continue
  58.         end-perform
  59. *
  60. * Now, let's get the first window
  61. *
  62.         move gw_hwndfirst to hwnd-type
  63.         call "GetWindow" with STDCALL using
  64.             by value this-window-handle
  65.             by value hwnd-type
  66.             returning child-window-handle
  67.         if child-window-handle = 0
  68.             move 3 to return-value
  69.             exit program
  70.         end-if
  71.        
  72.         move gw_hwndnext to hwnd-type  
  73. *
  74. * Now, let's see if this is the target window, if not, loop through all open windows
  75. *
  76.         perform until child-window-handle = 0
  77. *
  78. * Let's get the title bar text of this window
  79. *
  80.             call "GetWindowTextA" with STDCALL using
  81.                 by value child-window-handle
  82.                 by reference title-bar-buffer              
  83.                 by value title-bar-buffer-max
  84.                 returning length-of-title-bar-buffer        *> Note, the length returned does NOT include the NULL byte
  85. *
  86. * If the window has a title bar, is it the one we're looking for?
  87. *              
  88.             if length-of-title-bar-buffer > 0
  89.                 if title-bar-search-string(1:title-bar-index) = title-bar-buffer(1:title-bar-index)
  90.                     move 1 to found-window-sw
  91.                     move child-window-handle to found-window-handle
  92.                     move 0 to return-value
  93.                     exit program
  94.                 end-if
  95.             end-if
  96. *
  97. * Get the next window
  98. *
  99.             move child-window-handle to this-window-handle
  100.            
  101.             call "GetWindow" with STDCALL using
  102.                 by value this-window-handle
  103.                 by value hwnd-type
  104.                 returning child-window-handle
  105.        
  106.         end-perform
  107. *
  108. * Didn't find the window
  109. *
  110.         move 0 to return-value
  111.         move 0 to found-window-sw
  112.         move 0 to found-window-handle
  113.         exit program

Saludos ...
fastpho is offline   Responder Con Cita