Cobol Foro
Navegación en el Foro
Retroceder   Cobol Foro Entornos de desarrollo y compiladores Cobol Fujitsu COBOL PowerCOBOL (ActiveX, v4 - v11)
PowerCOBOL (ActiveX, v4 - v11) Versiones del IDE basadas en ActiveX
 
Otros temas que te pueden interesar
Tema Autor Foro Respuestas Último post
[Sintaxis] llamar a aplication externa .EXE hbetancur NetCOBOL 3 29 de mayo de 2021 11:58
[Sintaxis] Saber si un EXE se esta ejecutando ?? Hrmcobol PowerCOBOL y WinAPI 1 24 de noviembre de 2020 13:11
[Sintaxis] Compratir variable con un EXE de PowerCOBOL Recato53 PowerCOBOL (ActiveX, v4 - v11) 10 14 de febrero de 2017 17:18
[Compilador] Fujitsu Cobol for Windows Call EXE Joseg NetCOBOL 1 29 de octubre de 2016 23:18
[Compilador] Compilar un Ejecutable (.exe) Yonaider RM/COBOL 5 26 de mayo de 2016 09:19

Respuesta

  #1
Antiguo 5 de noviembre de 2024, 16:51
Joseg
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras en varias ocasiones 
Última Actividad 17.09.2026 18:23
Posts Posts: 401
Likes enviados Enviados: 130
Likes recibidos Recibidos: 179
Predeterminado Processo/EXE ativo
0 Inactivo Inactivo

Olá

Como saber en Powercobol se um processo esta ativo?

Gracias
Jose
Joseg is offline   Responder Con Cita
  #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
  #3
Antiguo 5 de noviembre de 2024, 22:46
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

@Joseg,

Código COBOL:
  1.  ENVIRONMENT     DIVISION.
  2.  DATA            DIVISION.
  3.  WORKING-STORAGE SECTION.
  4.  01  DWORD       typedef pic s9(9) comp-5.
  5.  01  ULONG_PTR   typedef pic  9(9) comp-5.
  6.  01  LONG        typedef pic s9(9) comp-5.
  7.  01  HANDLE      typedef pic s9(9) comp-5.
  8.  
  9. *>---------------------------------------------
  10.  01  TH32CS_SNAPPROCESS      type DWORD value h"02".
  11. *>---------------------------------------------
  12.  
  13.  01  PROCESSENTRY32.
  14.      05  dwSize              type DWORD.
  15.      05  cntUsage            type DWORD.
  16.      05  th32ProcessID       type DWORD.
  17.      05  th32DefaultHeapID        pointer.
  18.      05  th32ModuleID        type DWORD.
  19.      05  cntThreads          type DWORD.
  20.      05  th32ParentProcessID type DWORD.
  21.      05  pcPriClassBase      type LONG.
  22.      05  dwFlags             type DWORD.
  23.      05  szExeFile           pic x(1000).
  24.      
  25.  01  snapshot                type HANDLE.
  26.  
  27.  01  returnCode              type DWORD.
  28.  
  29.  PROCEDURE       DIVISION.
  30.  
  31.      call "CreateToolhelp32Snapshot" with stdcall using by value TH32CS_SNAPPROCESS
  32.                                                          by value 0
  33.                                                          returning snapshot
  34.      
  35.      move length of PROCESSENTRY32 to dwSize
  36.      
  37.      call "Process32First" with stdcall using by value snapshot
  38.                                               by reference PROCESSENTRY32
  39.                                               returning returnCode
  40.      
  41.      if  returnCode = 0
  42.          call "GetLastError" with stdcall returning returnCode
  43.          
  44.          display "GetLastError: ", returnCode
  45.          
  46.          exit program
  47.      end-if
  48.      
  49.      perform until returnCode = 0
  50.          if  szExeFile(1:8) = "Main.exe" *> resto a nulos
  51.              INVOKE pow-self "DisplayMessage" USING "Bingo!" 64
  52.          end-if
  53.                  
  54.          INVOKE CmList1 "AddString" USING szExeFile
  55.          
  56.          call "Process32Next" with stdcall using by value snapshot
  57.                                                  by reference PROCESSENTRY32
  58.                                                  returning returnCode
  59.      end-perform



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #4
Antiguo 7 de noviembre de 2024, 11:01
Joseg
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras en varias ocasiones 
Última Actividad 17.09.2026 18:23
Posts Posts: 401
Likes enviados Enviados: 130
Likes recibidos Recibidos: 179

Muchas gracias a todos por vuestra ayuda.

Eu pretendia fazer isto: https://www.tek-tips.com/threads/set...g-pid.1820890/
Apenas consegui fazer em "C" e Windev. Em anexo o código em "C".

Pero la idea era la siguiente: Con el número PID y no el título de la ventana (el título es dinámico), maximizar un programa de terceros y hacerse visible.

Código CPP:
  1. #include <windows.h>
  2. #include <tlhelp32.h>
  3. #include <iostream>
  4. #include <cstdlib>
  5.  
  6. BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
  7.     DWORD processId;
  8.     GetWindowThreadProcessId(hwnd, &processId);
  9.  
  10.     // Verificar se o PID corresponde e se a janela é visível
  11.     if (processId == static_cast<DWORD>(lParam) && IsWindowVisible(hwnd)) {
  12.         // Maximizar e trazer a janela para o primeiro plano
  13.         ShowWindow(hwnd, SW_MAXIMIZE);
  14.         SetForegroundWindow(hwnd);
  15.         return FALSE; // Parar a enumeração
  16.     }
  17.  
  18.     return TRUE; // Continuar a enumeração
  19. }
  20.  
  21. void MaximizeMainApplicationWindow(DWORD pid) {
  22.     EnumWindows(EnumWindowsProc, static_cast<LPARAM>(pid));
  23. }
  24.  
  25. int main(int argc, char* argv[]) {
  26.     if (argc != 2) {
  27.         std::cerr << "Usage: " << argv[0] << " <PID>" << std::endl;
  28.         return 1;
  29.     }
  30.  
  31.     DWORD pid = std::atoi(argv[1]);
  32.     MaximizeMainApplicationWindow(pid);
  33.  
  34.     return 0;
  35. }
Joseg is offline   Responder Con Cita
  #5
Antiguo 7 de noviembre de 2024, 12:33
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

@Joseg, desde que descubrí cómo hacer funcionar el CALL BY VALUE en PowerCOBOL, absolutamente todo lo que se puede hacer en C, también se puede hacer en PowerCOBOL!

Así que, este código C también se puede convertir en PowerCOBOL!



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #6
Antiguo 7 de noviembre de 2024, 18:00
Joseg
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras en varias ocasiones 
Última Actividad 17.09.2026 18:23
Posts Posts: 401
Likes enviados Enviados: 130
Likes recibidos Recibidos: 179

Citación del post de Kuk Ver Mensaje
@Joseg, desde que descubrí cómo hacer funcionar el CALL BY VALUE en PowerCOBOL, absolutamente todo lo que se puede hacer en C, también se puede hacer en PowerCOBOL!

Así que, este código C también se puede convertir en PowerCOBOL!
Admito que todo es posible ...pero no pude hacerlo, tampoco tengo mucha experiencia en llamadas a la API de WINDOWS.
Por ejemplo, esta función "&& IsWindowVisible(hwnd))" no devolvió el resultado correcto. Debo estar haciendo algo mal.

Código COBOL:
  1. CALL 'IsWindowVisible' USING BY VALUE HWND
  2. IF RETURN-CODE = 1
  3.    CALL 'ShowWindow' USING BY REFERENCE HWND,
  4.                                             BY VALUE 3   *> SW_MAXIMIZE
  5.    CALL 'SetForegroundWindow' USING BY REFERENCE HWND
  6.    IF RETURN-CODE = 1
  7.       DISPLAY "Janela trazida para frente com sucesso."
  8.   ELSE
  9.       DISPLAY "Falha ao trazer a janela para frente."
  10.    END-IF
  11. ELSE
  12.    DISPLAY "Janela não está visível."
  13. END-IF
José
Joseg is offline   Responder Con Cita
  #7
Antiguo 7 de noviembre de 2024, 21:58
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

@Joseg, acabo de probarlo y funciona:

Lo primero, creas un fichero nuevo en el directrio del proyecto y lo llamas EnumWindowsProc. Luego lo añades en el proyecto (import) y le pegas el siguiente contenido:

Código COBOL:
  1.  IDENTIFICATION DIVISION.
  2.  PROGRAM-ID. "EnumWindowsProc".
  3.  ENVIRONMENT     DIVISION.
  4.  DATA            DIVISION.
  5.  WORKING-STORAGE SECTION.
  6.  01  SW_MAXIMIZE          PIC S9(9) COMP-5 VALUE 3.
  7.  
  8.  01  P1                   POINTER.
  9.  01  HWND REDEFINES P1    PIC S9(9) COMP-5.
  10.  01  P2                   POINTER.
  11.  01  LPARAM REDEFINES P2  PIC S9(9) COMP-5.
  12.  
  13.  01  processId            PIC S9(9) COMP-5.
  14.  01  isVisble             PIC S9(9) COMP-5.
  15.  
  16.  LINKAGE SECTION.
  17.  77  PARM1                PIC S9(9) COMP-5.
  18.  77  PARM2                PIC  9(9) COMP-5.
  19.  
  20.  01  RETURN-VALUE         PIC  9(9) COMP-5.
  21.  
  22.  PROCEDURE DIVISION WITH STDCALL USING PARM1, PARM2 RETURNING RETURN-VALUE.
  23.      
  24.      MOVE FUNCTION ADDR(PARM1) TO P1
  25.      MOVE FUNCTION ADDR(PARM2) TO P2
  26.      
  27.      CALL "GetWindowThreadProcessId" WITH STDCALL USING BY VALUE HWND
  28.                                                         BY REFERENCE processId
  29.                                                        
  30.      CALL "IsWindowVisible" WITH STDCALL USING BY VALUE HWND RETURNING isVisble
  31.      
  32.      IF  processId = LPARAM AND
  33.          isVisble NOT = 0
  34.          CALL "ShowWindow"          WITH STDCALL USING BY VALUE HWND, SW_MAXIMIZE
  35.          CALL "SetForegroundWindow" WITH STDCALL USING BY VALUE HWND
  36.          
  37.          MOVE 0 TO RETURN-VALUE
  38.      
  39.      ELSE
  40.          MOVE 1 TO RETURN-VALUE
  41.      END-IF
  42.      
  43.      GOBACK
  44.      .
  45.          

No olvides de añadirle la directiva ALPHAL(WORD) en las propiedades.

Luego desde donde quieras haces algo así (yo lo hago en el evento Click de un botón, recogiendo un PID desde CmText):

Código COBOL:
  1.  ENVIRONMENT     DIVISION.
  2.  DATA            DIVISION.
  3.  WORKING-STORAGE SECTION.
  4.  01  ptr-EnumWindowsProc    procedure-pointer.
  5.  01  num-ptr redefines ptr-EnumWindowsProc pic s9(9) comp-5.
  6.  
  7.  01  pid         pic s9(9) comp-5.
  8.  PROCEDURE       DIVISION.
  9.  
  10.      move pow-numeric of CmText1 to pid
  11.      
  12.      set ptr-EnumWindowsProc to entry "EnumWindowsProc@8"
  13.      
  14.      call "EnumWindows" with stdcall using by value num-ptr
  15.                                            by value pid

Ya nos cuentas qué tal



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #8
Antiguo 8 de noviembre de 2024, 10:46
Joseg
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras en varias ocasiones 
Última Actividad 17.09.2026 18:23
Posts Posts: 401
Likes enviados Enviados: 130
Likes recibidos Recibidos: 179

Perfecto . Kuk entiendes mucho de esto !!
Gracias.

José
Joseg is offline   Responder Con Cita
  #9
Antiguo 8 de noviembre de 2024, 17:58
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

@Joseg, de nada, para eso estamos

El problema era que oficialmente Fujitsu COBOL no trabaja con BY VALUE, pero de esta manera "hackeamos" el compilador quitándole este handicap y hacemos funcionar los CALL BY VALUE. Y con esta solución podemos reescribir el Windows por completo si queremos



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #10
Antiguo 10 de noviembre de 2024, 16:57
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

@Joseg, he encontrado otra manera de hacerlo funcionar sin pasar por PROCEDURE-POINTER, lo cual me hace suponer que funcionaría incluso en PowerCOBOL v3 (que no tiene PROCEDURE-POINTER):

Código COBOL:
  1.  ENVIRONMENT     DIVISION.
  2.  DATA            DIVISION.
  3.  WORKING-STORAGE SECTION.
  4.  01  pid         pic s9(9) comp-5.
  5.  01  hModule     pic s9(9) comp-5.
  6.  01  pAddress    pic s9(9) comp-5.
  7.  
  8.  PROCEDURE       DIVISION.
  9.  
  10.      move pow-numeric of CmText1 to pid
  11.          
  12.      call "GetModuleHandleA" with stdcall using by value h"00" returning hModule
  13.          
  14.      call "GetProcAddress" with stdcall using by value hModule
  15.                                               by content "_EnumWindowsProc@8" & x"00"
  16.                                               returning pAddress
  17.      
  18.      call "EnumWindows" with stdcall using by value pAddress
  19.                                            by value pid

Funciona perfectamente, lo que pasa es que aquí uso WinAPI para obtener la dirección de la función.

A ver si un día lo pruebo en PowerCOBOL v3, debería funcionar, salvo que haya algún imprevisto.



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
Respuesta


Herramientas

Derechos de Publicación
No puedes publicar nuevos temas
No puedes publicar posts/responder
No puedes adjuntar archivos
No puedes editar tus posts

BB code is habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado

Saltar a Foro


La franja horaria es GMT +2. Ahora son las 14:57.
Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.