Sign in to follow this  
Followers 0
Ryan

Variable and PID question

15 posts in this topic

Hey guys,

The program reads a text file to find its variables. The program reads the txt file and gets the variables with no problems until it gets to..

;Choose Character
$file = FileOpen("config.txt", 0)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf

Then for some reason, the programs just sits there because its not getting a variable from the txt file.

If i type the variable into the script, then it has no problem.

But i would like the script to get the variables from the txt file.

Also...the program works with different windows that are labeled the same, so i had the script use a PID for everything. But the program also needs to use a PID for "SRO_Client". Is there a way to retrieve a PID for "SRO_Client" even though its started by another program, and not the script itself.

Main Script.....

Global $PID;Global variable to hold PID

$file = FileOpen("config.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Reads Config.txt file for variables
$fullAuto = FileReadLine($file, 1)
$CheatPatch = FileReadLine($file, 2)
$CheatEngine = FileReadLine($file, 3)
$batchPath = FileReadLine($file, 4)
$sbotpath = FileReadLine($file, 5)
$sbot = FileReadLine($file, 6)
$id = FileReadLine($file, 7)
$pass = FileReadLine($file, 8)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
$nextscriptpath= FileReadLine($file, 11)
$nextscriptname = FileReadLine($file, 12)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage");Shift-Alt-d

;;;; Body of program would go here;;;;
$sbotHandle = 0
If $fullAuto = 1 Then
;Start SBot
    $PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID)

;Start SRO_Client
;MouseClick("left", 200, 300)
    ControlClick("SBot", "", 169)
EndIf

;Wait for SRO_Client, safe for all resolutions
WinWait("SRO_Client", "")
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    $client = WinGetClientSize("SRO_Client", "")
    $pixel1 = $client[1] * 0.968
    $pixel2 = $client[0] * 0.073
    $pixel3 = $client[1] * 0.993
    $koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)
    If Not @error Then
        If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then
            ExitLoop
        EndIf
    EndIf
WEnd
Sleep(2000)
$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login
If $fullAuto = 1 Then
    Send("{BS}")
    Sleep(100)
    Send($id)
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send($pass)
    Sleep(2000)
EndIf
Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)
$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
$checksumImageCode = 0
$checksumImageCodeValid = 0
$checksumBlockedY = 0
If $client[1] < 700 Then
    $checksumBlockedY = 550
ElseIf $client[1] < 900 Then
    $checksumBlockedY = 660
Else
    $checksumBlockedY = $client[1] * 0.9 - 10
EndIf
$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)
Send("{ENTER}")


;Start Cheat Engine
If $fullAuto = 1 Then
    $PID = Run($CheatPatch & "\" & $CheatEngine, $CheatPatch);Read PID of new process
    WinWait("Cheat Engine", "")
    $WinHandle = _WinGetByPID($PID)
    If Not WinActive($WinHandle, "") Then
        WinActivate($WinHandle, "")
    EndIf
        Sleep(5000)
        $WinHandle = _WinGetByPID($PID)
        Sleep(1000)
        ControlClick($WinHandle, "", 169, "", 5)
        Sleep(1000)
        MouseClick ("left",25,50)
        Sleep(500)
        MouseClick ("left",410,250)
        Send ("{DOWN 150}")
        Sleep (500)
        Send ("{UP 1}")
        Sleep(500)
        Send ("{ENTER}")
        Sleep (500)
        MouseClick ("left", 910,250)
        Sleep(500)
        MouseClick ("left", 970,270)
        Sleep(500)
        Send("{BACKSPACE 3}")
        Sleep(500)
        Send("600")
        MouseClick ("left", 970,340)
EndIf

;Image Code Loop
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    Sleep(100)
    
    $state = 0
    $stateCounter = 0
    While 1
        Sleep(100)
        If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then
            $state = 2; logged in
            ExitLoop
        Else
            $checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
            If $checksumImageCodeTemp = $checksumLoginWindow Then
                $state = 0
                Sleep(500)
            Else
                If $checksumImageCodeValid = 0 Then
                    $checksumImageCode = $checksumImageCodeTemp
                    $checksumImageCodeValid = 1
                    $state = 1; image code
                    ExitLoop
                ElseIf $checksumImageCode = $checksumImageCodeTemp Then
                    $state = 1; image code
                    ExitLoop
                Else
                    $state = 0
                    $stateCounter = $stateCounter + 1
                    Sleep(500)
                    If $stateCounter > 10 Then
                        $checksumImageCode = $checksumImageCodeTemp
                        $state = 1; image code
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
    Sleep(100)
    
    
    If $state = 1 Then
  ;Image code
  ;Clear Screenshot directory
        RunWait($batchPath & "\clear_screenshots.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(1500)
  ;Take Screenshot
        Send("{PRINTSCREEN}")
        Sleep(1500)
  ;Call the decoder
        RunWait($batchPath & "\decode.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(100)
  ;Read the code
        $handle = FileOpen($batchPath & "\code.txt", 0)
        $code = FileReadLine($handle)
  ;Send the code
        Send($code)
        Sleep(100)
        Send("{ENTER}")
  ;Be sure this image code window disappeared before next loop,
  ;if a new image code window appears, continue on the new one
        Sleep(3000)
    ElseIf $state = 2 Then
  ;logged in
        ExitLoop
    EndIf
WEnd
;Logged in...
Sleep(2000)
WinKill("Cheat Engine")
;Choose Character
$file = FileOpen("config.txt", 0)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 2 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/4, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/4, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 3 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 3 Then
            MouseClick("left", $client[0]*5/6, $client[1]/2)
            $characterSelected = 1
        EndIf
    EndIf
EndIf
If $fullAuto = 1 And $characterSelected <> 0 Then
;Click on "Start" after character selection
    Sleep(1500)
    If $client[1] < 700 Then
        MouseClick("left", $client[0] - 268, 700)
    ElseIf $client[1] < 900 Then
        MouseClick("left", $client[0] - 268, 720)
    Else
        MouseClick("left", $client[0] - 268, $client[1] * 0.9)
    EndIf
    Sleep(3000)
;Start Auto Training :)
    $windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)
    
;Start Training
    ControlClick($sbotTitle, "", 538)
    Send("{TAB}")
    Sleep(100)
    Send("{DOWN 3}")
    Sleep(100)
    Send("{ENTER}")
    Sleep(3000)
    WinMinimizeAll()



;Click to go clientless
ControlClick($sbotTitle, "", 170)
Sleep(1500)
EndIf

;Runs next script

FileClose($file)
Exit
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

;=================NEW FUNCTION
Func _WinGetByPID($iPID)
    Local $aWList = WinList()
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            Return $aWList[$iCC][0]
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

Config.txt file.....

1
C:\Program Files\Cheat Engine
Cheat Engine.exe
C:\Documents and Settings\main\Desktop\Login Engine
C:\Documents and Settings\main\Desktop\Sbot\Red
SBot_1.22.exe
User
Pass
1
1 
C:\Documents and Settings\main\Desktop\Autologin Scripts\V1.2\character2
test.exe

Share this post


Link to post
Share on other sites



Check if the FileOpen could open the file successfully or make it more specific like:

$file = FileOpen(@ScriptDir & '\config.txt', 0)

To get all the PID of the specific process, use ProcessList and _ArraySearch to see if you don't have, yet, a PID(s) of this process in your global array.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is there a way to retrieve a PID for "SRO_Client" even though its started by another program, and not the script itself.

$PID=WinGetProcess("SRO_Client")

But i would like the script to get the variables from the txt file.

Instead of reinventing the wheel with FileReadLine, how about using IniRead to read stored variables in a file?

Also it looks like you're opening config.txt twice without using a fileclose after the first read. Maybe that's a problem?

Is the script hanging or exiting? Does it execute the indicated mouseclick?

Edited by TurionAltec

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

To get all the PID of the specific process, use ProcessList and _ArraySearch to see if you don't have, yet, a PID(s) of this process in your global array.

Thats a great idea, but my only problem is that...This script has to repeat it self about +5 times, all with different variables for $user, $pass, $sbotpath, etc.. So i have this script, renamed 5 times, all with their own variables, and the scripts will start each other after they end. *i know theirs a solution to only having 1 script looping with different variables each time, But i haven't found it yet*

$PID=WinGetProcess("SRO_Client")

Their will by multiple "SRO_Client"(S) open, and i need it to connect with the most recent "SRO_Client" that opened, so i need it to get more detailed.

Also it looks like you're opening config.txt twice without using a fileclose after the first read. Maybe that's a problem?

Because the script just hangs their, i tried reopening the file again, thinking that maybe it timeout or something

Is the script hanging or exiting? Does it execute the indicated mouseclick?

The script is just hanging, it wont even start the mouseclick, so im guessing its waiting for a variable to inform it on where to click.

Edited by Ryan

Share this post


Link to post
Share on other sites

Use ConsoleWrite($Variable) to see what is it's value, for debugging purpose. You'll need to post a demo of what you want to do with the 5 different processes using only one script.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Did it not work just getting the $character and $charactercount from the filereadline s in the beginning of the script?

Looping with different variables... perhaps put everything as a function so you can read the variables from a file, run the function, it will return, read new variables, run the function, return.

Also, if you're dealing with 5 scripts, it may really be worth while looking into iniread and ini files:

Don't be afraid to be generous with consolewrites:

;Choose Character
$file = FileOpen("config.txt", 0)
consolewrite("config.txt handle:"&$file&@CRLF)
$character = FileReadLine($file, 9)
Consolewrite("$character="&character&@crlf)
$characterCount = FileReadLine($file, 10)
Consolewrite("$charactercount="&charactercount&@crlf)
$characterSelected = 0
If $fullAuto = 1 Then
 consolewrite("$fullauto=1 true"&@CRLF)
    Sleep(1000)
    If $characterCount = 1 Then
        consolewrite("$charactercount=1 true"&@CRLF)
        If $character = 1 Then
            consolewrite("$character=1 true"&@CRLF)
            MouseClick("left", $client[0]/2, $client[1]/2)
           
            $characterSelected = 1
        EndIf
Edited by TurionAltec

Share this post


Link to post
Share on other sites

You'll need to post a demo of what you want to do with the 5 different processes using only one script.

I use this script to make a 5min process of loading programs and typing data, into a 1min process.

The script has to run multiple amount of times, each script with different variables, to load all the clients i have.

Did it not work just getting the $character and $charactercount from the filereadline s in the beginning of the script?

It works just fine, the script reads the $character and $charactercount. And ive tested it but entering a message box in the middle of the script, that informs me what their variables are. I dont understand why it just hangs their.

Looping with different variables... perhaps put everything as a function so you can read the variables from a file, run the function, it will return, read new variables, run the function, return.

I like that idea, i might try that..Thank you!

Also, if you're dealing with 5 scripts, it may really be worth while looking into iniread and ini files:

I actually am changing the scripting right now to use ini files.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

A good example would be to have an ini file:

[script1]
fullAuto = 1
CheatPatch = C:\Program Files\Cheat Engine
CheatEngine =Cheat Engine.exe
batchPath = C:\Documents and Settings\main\Desktop\Login Engine
sbotpath = C:\Documents and Settings\main\Desktop\Sbot\Red
sbot = SBot_1.22.exe
id = User
pass = Pass
character = 1
characterCount = 1
nextscriptpath= C:\Documents and Settings\main\Desktop\Autologin Scripts\V1.2\character2
nextscriptname = test.exe

[script2]
fullAuto = 1
CheatPatch = C:\Program Files\Cheat Engine
CheatEngine =Cheat Engine.exe
batchPath = C:\Documents and Settings\main\Desktop\Login Engine
sbotpath = C:\Documents and Settings\main\Desktop\Sbot\Red
sbot = SBot_1.22.exe
id = User
pass = Pass
character = 2
characterCount = 2
nextscriptpath= C:\Documents and Settings\main\Desktop\Autologin Scripts\V1.2\character3
nextscriptname = test.exe

then in your main script, move all your code into a function, say "RunAutomation()", then the main part of your script could look like this:

$fullAuto = IniRead("config.ini","script1","fullAuto","")
$CheatPatch = IniRead("config.ini","script1","Cheatpath","")
$CheatEngine = IniRead("config.ini","script1","Cheatengine","")
$batchPath = IniRead("config.ini","script1","batchpath","")
$sbotpath = IniRead("config.ini","script1","sbotpath","")
$sbot = IniRead("config.ini","script1","sbot","")
$id = IniRead("config.ini","script1","id","")
$pass = IniRead("config.ini","script1","pass","")
$character = IniRead("config.ini","script1","character","")
$characterCount = IniRead("config.ini","script1","charactercount","")
$nextscriptpath= IniRead("config.ini","script1","nextscriptpath","")
$nextscriptname = IniRead("config.ini","script1","nextscriptname","")

RunAutomation()

$fullAuto = IniRead("config.ini","script2","fullAuto","")
$CheatPatch = IniRead("config.ini","script2","Cheatpath","")
$CheatEngine = IniRead("config.ini","script2","Cheatengine","")
$batchPath = IniRead("config.ini","script2","batchpath","")
$sbotpath = IniRead("config.ini","script2","sbotpath","")
$sbot = IniRead("config.ini","script2","sbot","")
$id = IniRead("config.ini","script2","id","")
$pass = IniRead("config.ini","script2","pass","")
$character = IniRead("config.ini","script2","character","")
$characterCount = IniRead("config.ini","script2","charactercount","")
$nextscriptpath= IniRead("config.ini","script2","nextscriptpath","")
$nextscriptname = IniRead("config.ini","script2","nextscriptname","")

RunAutomation()

You'd also be able to use the ProcessList and _ArraySearch idea within the one script.

It works just fine, the script reads the $character and $charactercount. And ive tested it but entering a message box in the middle of the script, that informs me what their variables are. I dont understand why it just hangs there.

Through msgbox or whatnot (like consolewrite as suggested above, which works best if you're running from scite) narrow down exactly what line it's hanging on, rather than guess. Edited by TurionAltec

Share this post


Link to post
Share on other sites

Thank you TurionAltec. Im going to use your idea, and put it to use.

Share this post


Link to post
Share on other sites

So, i tried it out....and obviously i screwed up somewhere, because its not working :)

I know its a Func problem.

Global $PID;Global variable to hold PID

$fullAuto = IniRead("config.ini","Character1","fullauto","")
$CheatPatch = IniRead("config.ini","Character1","cheatpath","")
$CheatEngine = IniRead("config.ini","Character1","cheatengine","")
$batchPath = IniRead("config.ini","Character1","batchpath","")
$sbotpath = IniRead("config.ini","Character1","sbotpath","")
$sbot = IniRead("config.ini","Character1","sbot","")
$id = IniRead("config.ini","Character1","id","")
$pass = IniRead("config.ini","Character1","pass","")
$character = IniRead("config.ini","Character1","character","")
$characterCount = IniRead("config.ini","Character1","charactercount","")

Func RunAutomation()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage");Shift-Alt-d

;;;; Body of program would go here;;;;
$sbotHandle = 0
If $fullAuto = 1 Then
;Start SBot
    $PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID)

;Start SRO_Client
;MouseClick("left", 200, 300)
    ControlClick("SBot", "", 169)
EndIf

;Wait for SRO_Client, safe for all resolutions
WinWait("SRO_Client", "")
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    $client = WinGetClientSize("SRO_Client", "")
    $pixel1 = $client[1] * 0.968
    $pixel2 = $client[0] * 0.073
    $pixel3 = $client[1] * 0.993
    $koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)
    If Not @error Then
        If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then
            ExitLoop
        EndIf
    EndIf
WEnd
Sleep(2000)
$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login
If $fullAuto = 1 Then
    Send("{BS}")
    Sleep(100)
    Send($id)
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send($pass)
    Sleep(2000)
EndIf
Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)
$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
$checksumImageCode = 0
$checksumImageCodeValid = 0
$checksumBlockedY = 0
If $client[1] < 700 Then
    $checksumBlockedY = 550
ElseIf $client[1] < 900 Then
    $checksumBlockedY = 660
Else
    $checksumBlockedY = $client[1] * 0.9 - 10
EndIf
$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)
Send("{ENTER}")


;Start Cheat Engine
If $fullAuto = 1 Then
    $PID = Run($CheatPatch & "\" & $CheatEngine, $CheatPatch);Read PID of new process
    WinWait("Cheat Engine", "")
    $WinHandle = _WinGetByPID($PID)
    If Not WinActive($WinHandle, "") Then
        WinActivate($WinHandle, "")
    EndIf
        Sleep(5000)
        $WinHandle = _WinGetByPID($PID)
        Sleep(1000)
        ControlClick($WinHandle, "", 169, "", 5)
        Sleep(1000)
        MouseClick ("left",25,50)
        Sleep(500)
        MouseClick ("left",410,250)
        Send ("{DOWN 150}")
        Sleep (500)
        Send ("{UP 1}")
        Sleep(500)
        Send ("{ENTER}")
        Sleep (500)
        MouseClick ("left", 910,250)
        Sleep(500)
        MouseClick ("left", 970,270)
        Sleep(500)
        Send("{BACKSPACE 3}")
        Sleep(500)
        Send("600")
        MouseClick ("left", 970,340)
EndIf

;Image Code Loop
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    Sleep(100)
    
    $state = 0
    $stateCounter = 0
    While 1
        Sleep(100)
        If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then
            $state = 2; logged in
            ExitLoop
        Else
            $checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
            If $checksumImageCodeTemp = $checksumLoginWindow Then
                $state = 0
                Sleep(500)
            Else
                If $checksumImageCodeValid = 0 Then
                    $checksumImageCode = $checksumImageCodeTemp
                    $checksumImageCodeValid = 1
                    $state = 1; image code
                    ExitLoop
                ElseIf $checksumImageCode = $checksumImageCodeTemp Then
                    $state = 1; image code
                    ExitLoop
                Else
                    $state = 0
                    $stateCounter = $stateCounter + 1
                    Sleep(500)
                    If $stateCounter > 10 Then
                        $checksumImageCode = $checksumImageCodeTemp
                        $state = 1; image code
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
    Sleep(100)
    
    
    If $state = 1 Then
  ;Image code
  ;Clear Screenshot directory
        RunWait($batchPath & "\clear_screenshots.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(1500)
  ;Take Screenshot
        Send("{PRINTSCREEN}")
        Sleep(1500)
  ;Call the decoder
        RunWait($batchPath & "\decode.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(100)
  ;Read the code
        $handle = FileOpen($batchPath & "\code.txt", 0)
        $code = FileReadLine($handle)
        FileClose($handle)
  ;Send the code
        Send($code)
        Sleep(100)
        Send("{ENTER}")
  ;Be sure this image code window disappeared before next loop,
  ;if a new image code window appears, continue on the new one
        Sleep(3000)
    ElseIf $state = 2 Then
  ;logged in
        ExitLoop
    EndIf
WEnd
;Logged in...
Sleep(2000)
WinKill("Cheat Engine")
;Choose Character
$file = FileOpen("config.txt", 0)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 2 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/4, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/4, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 3 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 3 Then
            MouseClick("left", $client[0]*5/6, $client[1]/2)
            $characterSelected = 1
        EndIf
    EndIf
EndIf
If $fullAuto = 1 And $characterSelected <> 0 Then
;Click on "Start" after character selection
    Sleep(1500)
    If $client[1] < 700 Then
        MouseClick("left", $client[0] - 268, 700)
    ElseIf $client[1] < 900 Then
        MouseClick("left", $client[0] - 268, 720)
    Else
        MouseClick("left", $client[0] - 268, $client[1] * 0.9)
    EndIf
    Sleep(3000)
;Start Auto Training :)
    $windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)
    
;Start Training
    ControlClick($sbotTitle, "", 538)
    Send("{TAB}")
    Sleep(100)
    Send("{DOWN 3}")
    Sleep(100)
    Send("{ENTER}")
    Sleep(3000)
    WinMinimizeAll()

EndIf
Exit
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



$fullAuto = IniRead("config.ini","Character2","fullauto","")
$CheatPatch = IniRead("config.ini","Character2","cheatpath","")
$CheatEngine = IniRead("config.ini","Character2","cheatengine","")
$batchPath = IniRead("config.ini","Character2","batchpath","")
$sbotpath = IniRead("config.ini","Character2","sbotpath","")
$sbot = IniRead("config.ini","Character2","sbot","")
$id = IniRead("config.ini","Character2","id","")
$pass = IniRead("config.ini","Character2","pass","")
$character = IniRead("config.ini","Character2","character","")
$characterCount = IniRead("config.ini","Character2","charactercount","")

Func RunAutomation2()
    Global $PID;Global variable to hold PID

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage");Shift-Alt-d

;;;; Body of program would go here;;;;
$sbotHandle = 0
If $fullAuto = 1 Then
;Start SBot
    $PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID)

;Start SRO_Client
;MouseClick("left", 200, 300)
    ControlClick("SBot", "", 169)
EndIf

;Wait for SRO_Client, safe for all resolutions
WinWait("SRO_Client", "")
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    $client = WinGetClientSize("SRO_Client", "")
    $pixel1 = $client[1] * 0.968
    $pixel2 = $client[0] * 0.073
    $pixel3 = $client[1] * 0.993
    $koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)
    If Not @error Then
        If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then
            ExitLoop
        EndIf
    EndIf
WEnd
Sleep(2000)
$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login
If $fullAuto = 1 Then
    Send("{BS}")
    Sleep(100)
    Send($id)
    Sleep(100)
    Send("{TAB}")
    Sleep(100)
    Send($pass)
    Sleep(2000)
EndIf
Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)
$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
$checksumImageCode = 0
$checksumImageCodeValid = 0
$checksumBlockedY = 0
If $client[1] < 700 Then
    $checksumBlockedY = 550
ElseIf $client[1] < 900 Then
    $checksumBlockedY = 660
Else
    $checksumBlockedY = $client[1] * 0.9 - 10
EndIf
$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)
Send("{ENTER}")


;Start Cheat Engine
If $fullAuto = 1 Then
    $PID = Run($CheatPatch & "\" & $CheatEngine, $CheatPatch);Read PID of new process
    WinWait("Cheat Engine", "")
    $WinHandle = _WinGetByPID($PID)
    If Not WinActive($WinHandle, "") Then
        WinActivate($WinHandle, "")
    EndIf
        Sleep(5000)
        $WinHandle = _WinGetByPID($PID)
        Sleep(1000)
        ControlClick($WinHandle, "", 169, "", 5)
        Sleep(1000)
        MouseClick ("left",25,50)
        Sleep(500)
        MouseClick ("left",410,250)
        Send ("{DOWN 150}")
        Sleep (500)
        Send ("{UP 1}")
        Sleep(500)
        Send ("{ENTER}")
        Sleep (500)
        MouseClick ("left", 910,250)
        Sleep(500)
        MouseClick ("left", 970,270)
        Sleep(500)
        Send("{BACKSPACE 3}")
        Sleep(500)
        Send("600")
        MouseClick ("left", 970,340)
EndIf

;Image Code Loop
While 1
    If Not WinActive("SRO_Client", "") Then
        WinActivate("SRO_Client", "")
    EndIf
    Sleep(100)
    
    $state = 0
    $stateCounter = 0
    While 1
        Sleep(100)
        If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then
            $state = 2; logged in
            ExitLoop
        Else
            $checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)
            If $checksumImageCodeTemp = $checksumLoginWindow Then
                $state = 0
                Sleep(500)
            Else
                If $checksumImageCodeValid = 0 Then
                    $checksumImageCode = $checksumImageCodeTemp
                    $checksumImageCodeValid = 1
                    $state = 1; image code
                    ExitLoop
                ElseIf $checksumImageCode = $checksumImageCodeTemp Then
                    $state = 1; image code
                    ExitLoop
                Else
                    $state = 0
                    $stateCounter = $stateCounter + 1
                    Sleep(500)
                    If $stateCounter > 10 Then
                        $checksumImageCode = $checksumImageCodeTemp
                        $state = 1; image code
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
    Sleep(100)
    
    
    If $state = 1 Then
  ;Image code
  ;Clear Screenshot directory
        RunWait($batchPath & "\clear_screenshots.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(1500)
  ;Take Screenshot
        Send("{PRINTSCREEN}")
        Sleep(1500)
  ;Call the decoder
        RunWait($batchPath & "\decode.bat")
        Sleep(1000)
        If Not WinActive("SRO_Client", "") Then
            WinActivate("SRO_Client", "")
        EndIf
        Sleep(100)
  ;Read the code
        $handle = FileOpen($batchPath & "\code.txt", 0)
        $code = FileReadLine($handle)
        FileClose($handle)
  ;Send the code
        Send($code)
        Sleep(100)
        Send("{ENTER}")
  ;Be sure this image code window disappeared before next loop,
  ;if a new image code window appears, continue on the new one
        Sleep(3000)
    ElseIf $state = 2 Then
  ;logged in
        ExitLoop
    EndIf
WEnd
;Logged in...
Sleep(2000)
WinKill("Cheat Engine")
;Choose Character
$file = FileOpen("config.txt", 0)
$character = FileReadLine($file, 9)
$characterCount = FileReadLine($file, 10)
$characterSelected = 0
If $fullAuto = 1 Then
    Sleep(1000)
    If $characterCount = 1 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/2, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 2 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/4, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/4, $client[1]/2)
            $characterSelected = 1
        EndIf
    ElseIf $characterCount = 3 Then
        If $character = 1 Then
            MouseClick("left", $client[0]/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 2 Then
            MouseClick("left", $client[0]*3/6, $client[1]/2)
            $characterSelected = 1
        ElseIf $character = 3 Then
            MouseClick("left", $client[0]*5/6, $client[1]/2)
            $characterSelected = 1
        EndIf
    EndIf
EndIf
If $fullAuto = 1 And $characterSelected <> 0 Then
;Click on "Start" after character selection
    Sleep(1500)
    If $client[1] < 700 Then
        MouseClick("left", $client[0] - 268, 700)
    ElseIf $client[1] < 900 Then
        MouseClick("left", $client[0] - 268, 720)
    Else
        MouseClick("left", $client[0] - 268, $client[1] * 0.9)
    EndIf
    Sleep(3000)
;Start Auto Training :)
    $windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)
    
;Start Training
    ControlClick($sbotTitle, "", 538)
    Send("{TAB}")
    Sleep(100)
    Send("{DOWN 3}")
    Sleep(100)
    Send("{ENTER}")
    Sleep(3000)
    WinMinimizeAll()

EndIf
Exit
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

;=================NEW FUNCTION
Func _WinGetByPID($iPID)
    Local $aWList = WinList()
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            Return $aWList[$iCC][0]
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

Share this post


Link to post
Share on other sites

So, i tried it out....and obviously i screwed up somewhere, because its not working :)

I know its a Func problem.

You're failing to call the function, eg:

RunAutomation()

Func RunAutomation() just defines the function. Look at how _WinGetByPID is defined at the bottom of your script, and then called in the middle.

If RunAutomation() and RunAutomation2() are identical (other than the variables), don't put them as two different functions, that defeats the purpose of using a function, which lets you reuse code.

Something along the lines of

CODE
Global $PID;Global variable to hold PID

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")

HotKeySet("{ESC}", "Terminate")

HotKeySet("+!d", "ShowMessage");Shift-Alt-d

$fullAuto = IniRead("config.ini","Character1","fullauto","")

$CheatPatch = IniRead("config.ini","Character1","cheatpath","")

$CheatEngine = IniRead("config.ini","Character1","cheatengine","")

$batchPath = IniRead("config.ini","Character1","batchpath","")

$sbotpath = IniRead("config.ini","Character1","sbotpath","")

$sbot = IniRead("config.ini","Character1","sbot","")

$id = IniRead("config.ini","Character1","id","")

$pass = IniRead("config.ini","Character1","pass","")

$character = IniRead("config.ini","Character1","character","")

$characterCount = IniRead("config.ini","Character1","charactercount","")

RunAutomation()

$fullAuto = IniRead("config.ini","Character2","fullauto","")

$CheatPatch = IniRead("config.ini","Character2","cheatpath","")

$CheatEngine = IniRead("config.ini","Character2","cheatengine","")

$batchPath = IniRead("config.ini","Character2","batchpath","")

$sbotpath = IniRead("config.ini","Character2","sbotpath","")

$sbot = IniRead("config.ini","Character2","sbot","")

$id = IniRead("config.ini","Character2","id","")

$pass = IniRead("config.ini","Character2","pass","")

$character = IniRead("config.ini","Character2","character","")

$characterCount = IniRead("config.ini","Character2","charactercount","")

RunAutomation()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Press Esc to terminate script, Pause/Break to "pause"

Func RunAutomation()

;;;; Body of program would go here;;;;

$sbotHandle = 0

If $fullAuto = 1 Then

;Start SBot

$PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process

WinWait("SBot", "")

Sleep(5000)

$sbotHandle = _WinGetByPID($PID)

;Start SRO_Client

;MouseClick("left", 200, 300)

ControlClick("SBot", "", 169)

EndIf

;Wait for SRO_Client, safe for all resolutions

WinWait("SRO_Client", "")

While 1

If Not WinActive("SRO_Client", "") Then

WinActivate("SRO_Client", "")

EndIf

$client = WinGetClientSize("SRO_Client", "")

$pixel1 = $client[1] * 0.968

$pixel2 = $client[0] * 0.073

$pixel3 = $client[1] * 0.993

$koord = PixelSearch(0, $pixel1, $pixel2, $pixel3, 0xFF8080, 1)

If Not @error Then

If PixelGetColor($koord[0], $koord[1]) = 0xFF8080 Then

ExitLoop

EndIf

EndIf

WEnd

Sleep(2000)

$client = WinGetClientSize("SRO_Client", "")

MouseMove($client[0]-10, $client[1]/2)

;Login

If $fullAuto = 1 Then

Send("{BS}")

Sleep(100)

Send($id)

Sleep(100)

Send("{TAB}")

Sleep(100)

Send($pass)

Sleep(2000)

EndIf

Sleep(100)

$checksumLoginTop = PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12)

$checksumLoginWindow = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)

$checksumImageCode = 0

$checksumImageCodeValid = 0

$checksumBlockedY = 0

If $client[1] < 700 Then

$checksumBlockedY = 550

ElseIf $client[1] < 900 Then

$checksumBlockedY = 660

Else

$checksumBlockedY = $client[1] * 0.9 - 10

EndIf

$checksumBlocked = PixelChecksum(350, $checksumBlockedY, 400, $client[1] - 2)

Sleep(100)

Send("{ENTER}")

;Start Cheat Engine

If $fullAuto = 1 Then

$PID = Run($CheatPatch & "\" & $CheatEngine, $CheatPatch);Read PID of new process

WinWait("Cheat Engine", "")

$WinHandle = _WinGetByPID($PID)

If Not WinActive($WinHandle, "") Then

WinActivate($WinHandle, "")

EndIf

Sleep(5000)

$WinHandle = _WinGetByPID($PID)

Sleep(1000)

ControlClick($WinHandle, "", 169, "", 5)

Sleep(1000)

MouseClick ("left",25,50)

Sleep(500)

MouseClick ("left",410,250)

Send ("{DOWN 150}")

Sleep (500)

Send ("{UP 1}")

Sleep(500)

Send ("{ENTER}")

Sleep (500)

MouseClick ("left", 910,250)

Sleep(500)

MouseClick ("left", 970,270)

Sleep(500)

Send("{BACKSPACE 3}")

Sleep(500)

Send("600")

MouseClick ("left", 970,340)

EndIf

;Image Code Loop

While 1

If Not WinActive("SRO_Client", "") Then

WinActivate("SRO_Client", "")

EndIf

Sleep(100)

$state = 0

$stateCounter = 0

While 1

Sleep(100)

If $checksumLoginTop <> PixelChecksum(0, $client[1] * 0.08, $client[0] * 0.3, $client[1] * 0.12) Then

$state = 2; logged in

ExitLoop

Else

$checksumImageCodeTemp = PixelChecksum($client[0]/2 + 60, $client[1]/2 + 50, $client[0]/2 + 100, $client[1]/2 + 100)

If $checksumImageCodeTemp = $checksumLoginWindow Then

$state = 0

Sleep(500)

Else

If $checksumImageCodeValid = 0 Then

$checksumImageCode = $checksumImageCodeTemp

$checksumImageCodeValid = 1

$state = 1; image code

ExitLoop

ElseIf $checksumImageCode = $checksumImageCodeTemp Then

$state = 1; image code

ExitLoop

Else

$state = 0

$stateCounter = $stateCounter + 1

Sleep(500)

If $stateCounter > 10 Then

$checksumImageCode = $checksumImageCodeTemp

$state = 1; image code

ExitLoop

EndIf

EndIf

EndIf

EndIf

WEnd

Sleep(100)

If $state = 1 Then

;Image code

;Clear Screenshot directory

RunWait($batchPath & "\clear_screenshots.bat")

Sleep(1000)

If Not WinActive("SRO_Client", "") Then

WinActivate("SRO_Client", "")

EndIf

Sleep(1500)

;Take Screenshot

Send("{PRINTSCREEN}")

Sleep(1500)

;Call the decoder

RunWait($batchPath & "\decode.bat")

Sleep(1000)

If Not WinActive("SRO_Client", "") Then

WinActivate("SRO_Client", "")

EndIf

Sleep(100)

;Read the code

$handle = FileOpen($batchPath & "\code.txt", 0)

$code = FileReadLine($handle)

FileClose($handle)

;Send the code

Send($code)

Sleep(100)

Send("{ENTER}")

;Be sure this image code window disappeared before next loop,

;if a new image code window appears, continue on the new one

Sleep(3000)

ElseIf $state = 2 Then

;logged in

ExitLoop

EndIf

WEnd

;Logged in...

Sleep(2000)

WinKill("Cheat Engine")

;Choose Character

$file = FileOpen("config.txt", 0)

$character = FileReadLine($file, 9)

$characterCount = FileReadLine($file, 10)

$characterSelected = 0

If $fullAuto = 1 Then

Sleep(1000)

If $characterCount = 1 Then

If $character = 1 Then

MouseClick("left", $client[0]/2, $client[1]/2)

$characterSelected = 1

EndIf

ElseIf $characterCount = 2 Then

If $character = 1 Then

MouseClick("left", $client[0]/4, $client[1]/2)

$characterSelected = 1

ElseIf $character = 2 Then

MouseClick("left", $client[0]*3/4, $client[1]/2)

$characterSelected = 1

EndIf

ElseIf $characterCount = 3 Then

If $character = 1 Then

MouseClick("left", $client[0]/6, $client[1]/2)

$characterSelected = 1

ElseIf $character = 2 Then

MouseClick("left", $client[0]*3/6, $client[1]/2)

$characterSelected = 1

ElseIf $character = 3 Then

MouseClick("left", $client[0]*5/6, $client[1]/2)

$characterSelected = 1

EndIf

EndIf

EndIf

If $fullAuto = 1 And $characterSelected <> 0 Then

;Click on "Start" after character selection

Sleep(1500)

If $client[1] < 700 Then

MouseClick("left", $client[0] - 268, 700)

ElseIf $client[1] < 900 Then

MouseClick("left", $client[0] - 268, 720)

Else

MouseClick("left", $client[0] - 268, $client[1] * 0.9)

EndIf

Sleep(3000)

;Start Auto Training :party:

$windows = WinList()

$sbotTitle = "SBot"

For $i = 0 To $windows[0][0]

If $windows[$i][1] = $sbotHandle Then

$sbotTitle = $windows[$i][0]

ExitLoop

EndIf

Next

WinActivate($sbotTitle, "")

Sleep(6500)

;Start Training

ControlClick($sbotTitle, "", 538)

Send("{TAB}")

Sleep(100)

Send("{DOWN 3}")

Sleep(100)

Send("{ENTER}")

Sleep(3000)

WinMinimizeAll()

EndIf

Exit

EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('Script is "Paused"',0,0)

WEnd

ToolTip("")

EndFunc

Func Terminate()

Exit 0

EndFunc

Func ShowMessage()

MsgBox(4096,"","This is a message.")

EndFunc

;=================NEW FUNCTION

Func _WinGetByPID($iPID)

Local $aWList = WinList()

For $iCC = 1 To $aWList[0][0]

If WinGetProcess($aWList[$iCC][1]) = $iPID And _

BitAND(WinGetState($aWList[$iCC][1]), 2) Then

Return $aWList[$iCC][0]

EndIf

Next

Return SetError(1, 0, 0)

EndFunc

Also, using the [codebox ] tag in posts to wrap absurdly long chunks of code prevent excess scrolling.

Share this post


Link to post
Share on other sites

As far as retrieving the PID of the newest instance of "SRO_Client", assuming you know the process name, I started working on this routine, though it seems processlist() always returns oldest to newest, so the last value in the array is always the newest process. Here's a sample script that searches through an array of known PIDs to see if it isn't added:

#Include <Array.au3>

global $listofPIDs
global $newpid
$PIDtemp=ProcessList("notepad.exe")
For $i = 1 to $PIDtemp[0][0]
    _ArrayAdd($listofPIDs,$PIDtemp[$i][1])
Next
;_ArrayDisplay($listofPIDs, "Array")
$pid1=run("notepad.exe")

$PIDtemp=ProcessList("notepad.exe")
;_ArrayDisplay($PIDtemp,"Array")
ConsoleWrite($PIDtemp[0][0]&@CR)
For $i = 1 to $PIDtemp[0][0]
    _ArraySearch($listofPIDs,$PIDtemp[$i][1])
    If @error Then
        _ArrayAdd($listofPIDs,$PIDtemp[$i][1])
        $newpid=$PIDtemp[$i][1]
    EndIf
Next
MsgBox(0,"NewProcess","From Run:    "&$pid1&@CRLF& "From Search: "&$newpid)

Share this post


Link to post
Share on other sites

I wanna thank all of you guys for all your help. Ive really learned a lot from building this script, and i thank you guys for helping me and educating me more.

The script is almost done. YAHOO!!!

But 1 of my issues is that.

I changed the original scripting to this, because i needed to use PID.

$PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID)

But now, it screws up this portion of the scripting.

$windows = WinList()
    $sbotTitle = "SBot"
    For $i = 0 To $windows[0][0]
        If $windows[$i][1] = $sbotHandle Then
            $sbotTitle = $windows[$i][0]
            ExitLoop
        EndIf
    Next
    WinActivate($sbotTitle, "")
    Sleep(6500)

I now get the random #'s instead of the Title. Ive tried a few ideas of mine to fix it. But all ended in failure. :)

Share this post


Link to post
Share on other sites

Where are "random #s" causing a problem? As in in what function is it causing something to choke?

The "random numbers" are probably window handles, which are preferable for most commands because they are a unique identifier for each window. So I don't know why you go through all the effort to find a handle from the PID (using _WinGetByPID), then go through all the effort of getting the Title from that handle (using a weird inefficient search loop), only to issue WinActivate() using a title, when the handle is much more precise, and will differentiate better if there's several windows of the same title.

Also, if you want a title from a handle, you can use

$sbotTitle=WingetTitle($sbotHandle)

Maybe _WinGetByPID is returning the handle for a window from the application other than the Window you want? This modifies WinGetByPID to check only for Windows that match a passed title description. It should be quicker as well because it won't have to check every single window in the system.

;=================NEW FUNCTION
Func _WinGetByPID($iPID,$iTitle)
Local $aWList = WinList($iTitle)
For $iCC = 1 To $aWList[0][0]
If WinGetProcess($aWList[$iCC][1]) = $iPID And _
BitAND(WinGetState($aWList[$iCC][1]), 2) Then
Return $aWList[$iCC][0]
EndIf
Next
Return SetError(1, 0, 0)
EndFunc

Then modify the code:

$PID = Run($sbotpath & "\" & $sbot, $sbotpath);Read PID of new process
    WinWait("SBot", "")
    Sleep(5000)
    $sbotHandle = _WinGetByPID($PID, "SBot")

However it's still preferred to use

Winactivate($sbotHandle)

because you know it will get the right instance of "SBot"

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