Sign in to follow this  
Followers 0
oblivion

processID and find window help

5 posts in this topic

#1 ·  Posted (edited)

Ok so I searched through these forums for a couple of days and I can't seem to get the script I'm working on to work.

I want it to find the process CapWiz.exe and open up the minimized window for that process titled "CapWiz" and then send a keystroke "r" to that window and then exit the script, preferably without maximizing the window. This is what I have so far.

Option Explicit 

Dim oShell
Dim oAutoIt

Set oShell = WScript.CreateObject("WScript.Shell")
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

$iPid = ProcessExists("CapWiz.exe"); Will return the PID or 0 if the process isn't found.
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "CapWiz", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    
    While 1
        
; Get list of windows
        $aWin = WinList($sTitle)
        
; Searches thru all windows
        For $i = 1 To $aWin[0][0]
            
; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                
    ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                
    ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
                EndIf
            EndIf
        Next
        
; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
        
; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop
        
; Waits before new attempt
        Sleep(Opt("WinWaitDelay"))
    WEnd
    
    
; No matches
    SetError(1)
    Return 0

oAutoIt.WinWaitActive "CapWiz", ""

' Send some keystokes
oAutoIt.Send "r"



WScript.Quit
EndFunc;==>_ProcessGetHWnd
Edited by oblivion

Share this post


Link to post
Share on other sites



dono what is oAutoIt.Send "r"

ControlSend can send text to minimized windows

$opt = 1
Global $data, $prog = "notepad.exe"

If ProcessExists($prog) Then
    $iPid = ProcessExists($prog)
    _ProcessGetHWnd()
Else
    MsgBox(0,"ERROR","Process "&$prog&" Dont Exists")
    Exit
EndIf


While 1
    Sleep(10)
WEnd

Func _ProcessGetHWnd()
        $aWin = WinList()
        For $i = 1 To $aWin[0][0]
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                $data = $aWin[$i][1]
                Select
                Case $opt = 1
                    somefunc1()
                Case $opt = 2
                    somefunc2()
                EndSelect
            EndIf
        Next
EndFunc;==>_ProcessGetHWnd

Func somefunc1()
    WinSetState($data ,"",@SW_MINIMIZE)
    ControlSend($data , "", "Edit1", "This is a line of text in the notepad window")
    WinSetState($data ,"",@SW_MAXIMIZE)
    MsgBox(0,"","bb")
    Exit
EndFunc

Func somefunc2()
    WinSetState($data ,"",@SW_MINIMIZE)
    WinActivate($data ,"")
    WinWaitActive($data ,"")
    Send("r")
    MsgBox(0,"","bb")
    Exit
EndFunc

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

:Confused: In which language it's supposed to be written?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

:Confused: In which language it's supposed to be written?

autoitX :)

WinWaitActive "title", ["text"], [timeout]

 

title is the only required parameter for this function, both the text and timeout are optional.  In some functions the text parameter is not optional, if you do not wish to specify any text then just use "" (a blank string).  A blank string, or nothing at all, in the text tells AutoIt that any text is valid.

 

To use the above function with any notepad window both these methods will work:

oAutoIt.WinWaitActive "Untitled - Notepad"

AutoIt Forums > AutoIt v3 > ActiveX/COM Help and Support (AutoItX)

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

One problem I had with hWnd's and proc ID's is that there are often many hWnd for each proc, whereas one often assumes there is a one-to-one relationship. At first I could not figure out why the hWnd I pulled from the proc ID would not work when I tried to use it to send clicks into the window. If you are having a similar problem, you will probably find that although there may be many hWnd's, most of them will have a blank window name. This gives you something to discriminate which is the "real" hWnd.

Regards - Jeremy

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0