Jump to content

Recommended Posts

Posted (edited)

Hi.

Here's the problem :
I have a C++ console program which i have the PID of and would like to work on, however autoit only works with hWnd/title/class.
The thing is, i can't use the hWnd or title because the console doesn't have any. I get the hWnd by using _WinAPI_EnumProcessWindows.
I don't know how to retrieve something i can work with.

Would you have any idea ?

Demo :

#include <WinAPIProc.au3> ; _WinAPI_EnumProcessWindows
#Include <Array.au3> ; _ArrayDisplay

$pid = ShellExecute(@SystemDir & "\cmd.exe")
$array = _WinAPI_EnumProcessWindows($pid, False)

If IsArray($array) Then
    _ArrayDisplay($array)
Else
    MsgBox(0,"", "$array is not an array. Error code : " & @error & " PID : " & $pid)
EndIf

 

Edited by Cotino
Posted

Maybe this works:

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Posted (edited)

Works if the cmd was already opened and i write the PID manually, but doesn't work if the cmd is opened with ShellExecute.

Still going to be a problem if there are several console opened though.

Edit : My bad i'm blind, didn't see your comment to retrieve the handle ~

Edited by Cotino
Posted

Did some tweaks to fit my style but all in all it works like a charm.

Thanks funkey !

Func _WinGetHandle($pid)

    Local $winList = WinList()

    For $i = 1 To $winList[0][0]
        ConsoleWrite("@@ " & $i & " | " & WinGetProcess($winList[$i][0]) & " | " & $winList[$i][0] & " | " & $winList[$i][1] & @CRLF)
        If $pid = WinGetProcess($winList[$i][1]) Then
            Return $winList[$i][1]
        EndIf
    Next

    SetError(1)
    Return 0

EndFunc

Func _WinGetTitle($pid)

    Local $winList = WinList()

    For $i = 1 To $winList[0][0]
        ConsoleWrite("@@ " & $i & " | " & WinGetProcess($winList[$i][0]) & " | " & $winList[$i][0] & " | " & $winList[$i][1] & @CRLF)
        If $pid = WinGetProcess($winList[$i][1]) Then
            Return $winList[$i][0]
        EndIf
    Next

    SetError(1)
    Return 0

EndFunc

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...