#NoTrayIcon
If Not $CmdLine[0] Then Exit -1
Global $Au3Check = CheckFile("Au3Check.exe")
Global $64
For $i = 1 To $CmdLine[0]
If $CmdLine[$i] = "/64" Or $CmdLine[$i] = "-64" Then
$64 = True
$CmdLine[$i] = ""
EndIf
Next
If $64 And @OSArch = "X86" Then
ConsoleWrite("!> " & @ScriptName & " : Can't run AutoIt3_x64 because OS is x86" & @CRLF)
Exit -1
EndIf
If $64 Then
Global $AutoIt3 = CheckFile("AutoIt3_x64.exe")
Else
Global $AutoIt3 = CheckFile("AutoIt3.exe")
EndIf
Global $Output, $Line, $ErrCode, $PID
$ErrCode = GetExitCode($Au3Check & ' "' & $CmdLine[1] & '"', False)
If Not $ErrCode Then
$Line = ' "' & $CmdLine[1] & '"'
For $i = 2 To $CmdLine[0]
$Line &= " " & $CmdLine[$i]
Next
$ErrCode = GetExitCode($AutoIt3 & " /ErrorStdOut" & $Line)
If $ErrCode Then MarkErrLine()
Exit $ErrCode
Else
ConsoleWrite(StdoutRead($PID))
MarkErrLine()
Exit $ErrCode
EndIf
Func CheckFile($FileName)
Local $FilePath = @ScriptDir & "\" & $FileName
If Not FileExists($FilePath) Then
$FilePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\" & $FileName
If Not FileExists($FilePath) Then
ConsoleWrite("!> " & @ScriptName & " : File not found '" & $FileName & "'" & @CRLF)
Exit -1
EndIf
EndIf
Return $FilePath
EndFunc
Func GetExitCode($Str, $Read = True)
Local $aOP, $aEC, $ExitCode = -1
$PID = Run($Str, "", @SW_HIDE, 8)
If Not $PID Then Return $ExitCode
$aOP = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", 0x400, "bool", 0, "dword", $PID)
If $Read Then
While Sleep(10)
$Output = StdoutRead($PID)
If @error Then ExitLoop
If @extended Then ConsoleWrite($Output)
WEnd
EndIf
While ProcessExists($PID)
Sleep(10)
WEnd
If IsArray($aOP) Then
$aEC = DllCall("kernel32.dll", "bool", "GetExitCodeProcess", "handle", $aOP[0], "dword*", 0)
If Not @error Then $ExitCode = $aEC[2]
DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aOP[0])
EndIf
Return $ExitCode
EndFunc
Func MarkErrLine()
WinActivate("[class:SciTEWindow]")
Send("{F4}")
EndFunc