Results 1 to 3 of 3

Thread: [a challenge!] interacting with running programs

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    1

    Post

    Anybody know how to trace actual commands being sent from a program that is running shelled from you app? Not tracing all system action but the actions going on. If you do, have you ever written anything to interact with any Adobe Products?

    Truth!Justice!Honor!Loyalty!And brushing your teeth!

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    Oporto, Portugal
    Posts
    134

    Post

    Here's a code suplied by Aaron Young that does it:
    Here's an Example I've put together which retrieves any Text associated with a Window or its Children, it uses the SendMessage API with the WM_GETTEXT Constant to retrieve the Text instead of the GetWindowText API as it's used only for retrieving Caption Text associated with a Window Handle.
    Place a Multiline Textbox and a Timer Control on a Form..
    In a Module..
    code:


    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const WM_GETTEXT = &HD
    Public Const WM_GETTEXTLENGTH = &HE
    Public sText As String
    Public Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sBuffer As String
    Dim lBuffLen As Long

    'Return Zero to Finish Enumerating Child Windows
    EnumProc = hwnd
    'Get the Text Associated with this Child Window Handle..
    lBuffLen = SendMessage(hwnd, WM_GETTEXTLENGTH, 0&, ByVal 0&) + 1
    sBuffer = Space(lBuffLen)
    Call SendMessage(hwnd, WM_GETTEXT, lBuffLen, ByVal sBuffer)
    'Add the Text to our String Buffer
    sText = sText & Replace(sBuffer, Chr(0), "") & vbCrLf
    'Now Enumerate the Child Windows of this Child Window (Recursion)
    'To do this we need to replicate the Enum Function..
    Call EnumChildWindows(hwnd, AddressOf EnumChildProc, 0&)
    End Function
    Private Function EnumChildProc(ByVal hwnd As Long, lParam As Long) As Long
    Dim sBuffer As String
    Dim lBuffLen As Long

    'Replica of the EnumProc Function used for Recursively Enumerating Child Windows
    EnumChildProc = hwnd
    lBuffLen = SendMessage(hwnd, WM_GETTEXTLENGTH, 0&, ByVal 0&) + 1
    sBuffer = Space(lBuffLen)
    Call SendMessage(hwnd, WM_GETTEXT, lBuffLen, ByVal sBuffer)
    sText = sText & Replace(sBuffer, Chr(0), "") & vbCrLf
    Call EnumChildWindows(hwnd, AddressOf EnumProc, 0&)
    End Function


    In the Form..
    code:


    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Const VK_LBUTTON = &H1
    Private Sub Form_Load()
    Timer1.Interval = 100
    End Sub
    Private Sub Timer1_Timer()
    Dim lHwnd As Long
    Dim tPOS As POINTAPI
    Dim lBuffLen As Long

    If GetAsyncKeyState(VK_LBUTTON) Then
    'Left Mouse Button Down, Get the Cursors Coords..
    Call GetCursorPos(tPOS)
    'Get the Window Handle for the Window Under the Mouse Cursor
    lHwnd = WindowFromPoint(tPOS.x, tPOS.y)
    'Only process if it's not our own Form..
    If lHwnd <> hwnd And GetParent(lHwnd) <> hwnd Then
    'Make sure we have the Parent Window Handle
    If GetParent(lHwnd) Then lHwnd = GetParent(lHwnd)
    'Get the Parents Text, usually a Caption..
    lBuffLen = SendMessage(lHwnd, WM_GETTEXTLENGTH, 0&, ByVal 0&) + 1
    sText = Space(lBuffLen)
    Call SendMessage(lHwnd, WM_GETTEXT, lBuffLen, ByVal sText)
    sText = Replace(sText, Chr(0), "") & vbCrLf
    'Now Enumerate ALL Child Windows, ie. Command Buttons, Lists, Textboxes, etc..
    Call EnumChildWindows(lHwnd, AddressOf EnumProc, 0&)
    'Display the Retrieved Text
    Text1 = sText
    'Wait until the Mouse if Released
    While GetAsyncKeyState(VK_LBUTTON)
    DoEvents
    Wend
    End If
    End If

    End Sub


    Point and Click on a Window to see ALL text associated with it, ie. Open Notepad, type something then Click it while Running this Example.
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected] <mailto:[email protected]>
    [email protected] <mailto:[email protected]>


    Jorge Ledo
    [email protected]

    P.S. - Aaron please excuse me for the abuse of publishing your code. I assume there is no problem 'cause it was published by you in a previous reply.

  3. #3
    Junior Member
    Join Date
    Nov 1999
    Posts
    27

    Post

    It depends on the app that is being shelled. Does it write to a log or something that your app can read after it issues the shell command? Once you shell out it is all up to the app being shelled to leave some type of trail for you to read.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width