• Windows - Get window object (or title) from PID

    From Garry Smithwick@21:1/5 to All on Sun Jan 14 08:01:31 2018
    Rxwinexec returns the PID for the task started. I need to get the window object or the window title associated with the PID. Anyone have ideas on how to do this? Thanks

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jack@21:1/5 to Garry Smithwick on Mon Jan 15 10:10:43 2018
    On 1/14/2018 11:01 AM, Garry Smithwick wrote:
    Rxwinexec returns the PID for the task started. I need to get the window object or the window title associated with the PID. Anyone have ideas on how to do this? Thanks


    I have a routine to see if Thunderbird is running or not. It uses the
    windows utility "tasklist" that gets all running sessions. The first
    column is the app name, the second is the PID. My routine looks for the
    Name, but you could easily modify it to look for the PID and return the
    file name for that PID.

    /**************************************************************************************************
    * FUNCTION: Check_Tbird
    * Use DOS Tasklist.exe to get running tasks, and pipe through rxqueue. *
    If Thunderbird.exe is active, return "YES" to calling function. **************************************************************************************************/

    Check_Tbird: Procedure
    TBird = "NO"
    TBird_Que = rxqueue("Create")
    rc = rxqueue("set",TBird_Que)
    "tasklist | rxqueue" TBird_Que
    i=1
    do queued()
    pull aline.i
    if pos("THUNDERBIRD.EXE",aline.i) >0 then TBird = "YES"
    i=i+i
    end
    Call rxqueue "DELETE", TBird_Que

    Return TBird /****************************************************************************************************************/


    --
    Jack
    Tolerance is the virtue of the man without convictions.
    http://jbstein.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Garry Smithwick@21:1/5 to Jack on Mon Jan 15 10:50:09 2018
    On Monday, January 15, 2018 at 10:10:47 AM UTC-5, Jack wrote:
    On 1/14/2018 11:01 AM, Garry Smithwick wrote:
    Rxwinexec returns the PID for the task started. I need to get the window object or the window title associated with the PID. Anyone have ideas on how to do this? Thanks


    I have a routine to see if Thunderbird is running or not. It uses the windows utility "tasklist" that gets all running sessions. The first
    column is the app name, the second is the PID. My routine looks for the Name, but you could easily modify it to look for the PID and return the
    file name for that PID.

    /**************************************************************************************************
    * FUNCTION: Check_Tbird
    * Use DOS Tasklist.exe to get running tasks, and pipe through rxqueue. *
    If Thunderbird.exe is active, return "YES" to calling function. **************************************************************************************************/

    Check_Tbird: Procedure
    TBird = "NO"
    TBird_Que = rxqueue("Create")
    rc = rxqueue("set",TBird_Que)
    "tasklist | rxqueue" TBird_Que
    i=1
    do queued()
    pull aline.i
    if pos("THUNDERBIRD.EXE",aline.i) >0 then TBird = "YES"
    i=i+i
    end
    Call rxqueue "DELETE", TBird_Que

    Return TBird /****************************************************************************************************************/


    --
    Jack
    Tolerance is the virtue of the man without convictions.
    http://jbstein.com

    I have a routine like that also. However, that will not get me the window object or the window title associated with the PID.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Garry Smithwick@21:1/5 to All on Wed Jan 17 07:17:11 2018
    Rexx code to test RxWinExecPlus:

    browser = '"C:\Program Files\Internet Explorer\iexplore.exe"'

    url = '"http://www.google.com/"'

    Parse Value RxWinExecPlus(browser url) With PID WindowTitle

    Say 'Window title:' WindowTitle

    WindowObject = .local~WindowObject

    Say 'Coordinates:' WindowObject~coordinates

    WindowObject~toForeground
    WindowObject~MoveTo(0,0)

    Say 'Move to:' WindowObject~coordinates

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Garry Smithwick@21:1/5 to All on Wed Jan 17 07:16:03 2018
    This is not foolproof, but it works most of the time.

    RxWinExecPlus.rex

    -- Input: Arg(1) And Arg(2) same as RxWinExec, Arg(3) equal Syssleep time value

    -- RxWinExecPls written by Garrysmithwick@gmail.com (January 2018)

    OpenWindows = OpenWindowsArray()

    PID = RxWinExec(Arg(1), Word(Arg(2) 'ShowNormal',1))

    If PID < 32 Then Return 'Error'pid SysGetErrortext(pid)

    Parse Value Arg(3) '1' With SleepTime .

    If Datatype(SleepTime,'N') Then Call Syssleep SleepTime

    Windows = OpenWindowsArray()

    Do 5
    Do n = 1 to windows~items
    If OpenWindows~hasItem(windows[n]) = 0 Then Do
    .local~WindowObject = object.n
    Return pid .local~WindowObject~title
    End
    End
    Call Syssleep 1
    End

    Return 'Error99 Not new window found'


    -- Build an array of all visible enabled, visible, no-blank window titles OpenWindowsArray:

    windows = .array~new

    mgr = .WindowsManager~new

    child = mgr~DesktopWindow~FirstChild

    Do While child <> .nil
    Select
    When child~State~Pos("Invisible") > 0 Then nop
    When child~State~Pos("Disabled") > 0 Then nop
    When Strip(child~title) = '' Then nop
    Otherwise Do
    index = windows~append(child~title)
    object.index = child
    End
    End
    child = child~next
    End

    Return windows

    ::requires 'winsystm.cls'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jack@21:1/5 to Garry Smithwick on Sun Jan 21 13:16:15 2018
    On 1/15/2018 1:50 PM, Garry Smithwick wrote:
    On Monday, January 15, 2018 at 10:10:47 AM UTC-5, Jack wrote:
    On 1/14/2018 11:01 AM, Garry Smithwick wrote:
    Rxwinexec returns the PID for the task started. I need to get the window object or the window title associated with the PID. Anyone have ideas on how to do this? Thanks


    I have a routine to see if Thunderbird is running or not. It uses the
    windows utility "tasklist" that gets all running sessions. The first
    column is the app name, the second is the PID. My routine looks for the
    Name, but you could easily modify it to look for the PID and return the
    file name for that PID.

    /**************************************************************************************************
    * FUNCTION: Check_Tbird
    * Use DOS Tasklist.exe to get running tasks, and pipe through rxqueue. *
    If Thunderbird.exe is active, return "YES" to calling function.
    **************************************************************************************************/

    Check_Tbird: Procedure
    TBird = "NO"
    TBird_Que = rxqueue("Create")
    rc = rxqueue("set",TBird_Que)
    "tasklist | rxqueue" TBird_Que
    i=1
    do queued()
    pull aline.i
    if pos("THUNDERBIRD.EXE",aline.i) >0 then TBird = "YES"
    i=i+i
    end
    Call rxqueue "DELETE", TBird_Que

    Return TBird
    /****************************************************************************************************************/


    --
    Jack
    Tolerance is the virtue of the man without convictions.
    http://jbstein.com

    I have a routine like that also. However, that will not get me the window object or the window title associated with the PID.

    Not sure why? Tasklist returns all running applications, their Name,
    PID, Session Name, Session# and Mem Usage. Rexx can pull out any/all of
    those items if you know the PID.

    If pos(PID,aline.i) >0 then (parse line as you wish)

    --
    Jack
    Tolerance is the virtue of the man without convictions.
    http://jbstein.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Garry Smithwick@21:1/5 to All on Mon Jan 22 05:11:26 2018
    Yes, tasklist list gives me lots of data, but not the windowobject. The challenge is to get the windowobject using the PID and then get the window title using the windowobject. In other words, given the PID of a task, what is the window title
    associated with that PID?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jack@21:1/5 to Garry Smithwick on Tue Jan 23 11:22:26 2018
    On 1/22/2018 8:11 AM, Garry Smithwick wrote:
    Yes, tasklist list gives me lots of data, but not the windowobject. The challenge is to get the windowobject
    using the PID and then get the window title using the windowobject. In other words, given the PID of a task,
    what is the window title associated with that PID?

    OK, that makes sense. I was assuming the Image Name given in task list
    was the also the window title. I now see that this is not the case,
    just sometimes. My rexx scripts show up in tasklist as a Rexx process,
    no title, although the window title does show up in the title bar, so
    windows seems to have the info since it puts it in the title bar? EXE's alsways show up in tasklist with the Image Name the same as the window
    title. I could easily be confused between image names, window titles
    and window object.

    I recall many years ago doing this type of thing with OS/2 and object
    ids and pids, not with MSWindows.

    --
    Jack
    Tolerance is the virtue of the man without convictions.
    http://jbstein.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)