Sign in to follow this  
Followers 0
Prego

Running Multiple EXE files

12 posts in this topic

I am tryign to run multiple EXE files. The files are all in 1 folder and i want it to run 1 file when it is fininshe run the second file and so on until all files are run. When they are run i want the Loop to end. Here is what i have so far.

Func Multiple ($Path1)

$Search = FileFindFirstFile($Path1 & '*.exe')

If $Search = -1 Then

SetError(0)

Else

$PID = RunWait($Path1 & $client[1] & '*.exe')

WinWait($Client, 'Install', 60)

ClickOn($Client, 'Install', 'Button1', 100)

Sleep(60000)

ProcessWaitClose('PrnInstall.exe')

WinWaitActive($Client, 'Install', 60)

ClickOn($Client, 'Install', 'Button2',100)

Wait($PID)

While 1

$EXE = FileFindNextFile($Search)

If @error Then ExitLoop

$CueText = ' Installing Printers ' & $EXE & ' ...'

ControlSetText($CueTitle, "",'Static1', @CRLF&$CueText)

TrayTip($CueTitle, $CueText, 10)

RunWait($Path1 & $EXE)

WEnd

SetError(0)

FileClose($Search)

EndIf

EndFunc ;==>Installing multiple printer on a machine

The line in red is the one i am hanging up on. i believe it has somethign to do with the *.exe. If i put in a single file name it works but will only run 1 file and not the others. Any help would be appreciated. thanks

Share this post


Link to post
Share on other sites



#include <file.au3>

$rootFolder = "C:\"

$fileArray = _FileListToArray($rootFolder, "*.exe", 1)

For $X = 1 to $fileArray[0]
RunWait($rootFolder & "\" & $fileArray[$X])
Next

Share this post


Link to post
Share on other sites

As i am still fairly new to this and am not too familiar with Array. I keep getting a error with <file.au3> no EndFunc in line 24 it is there so i am puzzled. Is there another way of doign this???

#include <file.au3>

$rootFolder = "C:\"

$fileArray = _FileListToArray($rootFolder, "*.exe", 1)

For $X = 1 to $fileArray[0]
RunWait($rootFolder & "\" & $fileArray[$X])
Next

Share this post


Link to post
Share on other sites

Thats strange, what version of AutoIt are you running? Can you copy the error from the SciTe window?

RunWait is probably not going to work for you, this will freeze your script until the program returns. You seem so be interacting with the running program so you will have to use Run().

Share this post


Link to post
Share on other sites

ERROR

-------------------------------------

Line 24 (File "c:\Program Files\AutoIt3\include\file.au3"):

func_FileCoutnLines ($sFilePath)

Error: "Func" statement has no matchine "EndFunc".

---------------------------------------

I am using AutoIt v3

Liek i said i am very new to AutoIt...

Thanks Again

Share this post


Link to post
Share on other sites

ERROR

-------------------------------------

Line 24 (File "c:\Program Files\AutoIt3\include\file.au3"):

func_FileCoutnLines ($sFilePath)

Error: "Func" statement has no matchine "EndFunc".

---------------------------------------

I am using AutoIt v3

Liek i said i am very new to AutoIt...

Thanks Again

Most likely a EndIf or a WEnd not accounted for.

1. There is a typo in your _FileCountLines, you have _FileCoutnLines :D

2. To tell what version you are using, you can do a simple Message Box: MsgBox(64, "Version", @AutoItVersion) (that gives the info weaponx was requesting)

3. If fixing the typo in 1. doesn't fix it, then Open the file.au3 file from the include file.

From the beginning of the function: Func _FileCountLines to the end of the function, copy and paste it here.

When pasting it, make sure you wrap it in [code ]**paste here**[ /code] tags (no spaces in the tabs, only shown spaces so you could see how to use them)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

1.. the typo was my misspelling it is correct in the file

2.. Version is -= 3.2.10.0

3...

-----------------------------------------

Func_FileCountLines($sFilePath)

Local $N = FileGetSize($sFilePath) - 1

If @error Or $N = -1 Then Return 0

Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1

EndFunc ;==>_FileCountLines

---------------------------------------------

Most likely a EndIf or a WEnd not accounted for.

1. There is a typo in your _FileCountLines, you have _FileCoutnLines :D

2. To tell what version you are using, you can do a simple Message Box: MsgBox(64, "Version", @AutoItVersion) (that gives the info weaponx was requesting)

3. If fixing the typo in 1. doesn't fix it, then Open the file.au3 file from the include file.

From the beginning of the function: Func _FileCountLines to the end of the function, copy and paste it here.

When pasting it, make sure you wrap it in [code ]**paste here**[ /code] tags (no spaces in the tabs, only shown spaces so you could see how to use them)

Edited by Prego

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi,

I don't know what you exactly mean, but maybe ..., hmmm, anyway ..., try this:

Func Multiple ($Path1)
    
    Local $hSearch, $Client, $CueText, $CueTitle, $PID, $EXE
    $hSearch = FileFindFirstFile($Path1 & '*.exe')
    If $hSearch = -1 Then
        Return SetError(0) ; returns 0
    Else
        ; RunWait returns the exitcode of the applicaton
        ; when it closes(!) and no PID ...
;~         $PID = RunWait($Path1 & $Client[1] & '*.exe')
        $PID = Run($Path1 & $Client[1] & '*.exe')
        ; is this here waiting for the window of $Path1 & $Client[1] & '*.exe' ?
        ; at this point of yur script $Path1 & $Client[1] & '*.exe' is ended if you use RunWait.
        If WinWait($Client, 'Install', 60) Then
            ClickOn($Client, 'Install', 'Button1', 100)
;~             Sleep(60000) ; 1 minute ?!
            ProcessWaitClose('PrnInstall.exe')
            If WinWaitActive($Client, 'Install', 60) Then
                ClickOn($Client, 'Install', 'Button2',100)
                Wait($PID)
                While 1
                    $EXE = FileFindNextFile($hSearch)
                    If @error Then ExitLoop
                    $CueText = ' Installing Printers ' & $EXE & ' ...'
                    ControlSetText($CueTitle, "",'Static1', @CRLF&$CueText)
                    TrayTip($CueTitle, $CueText, 10)
                    $iExitCode = RunWait($Path1 & $EXE)
                WEnd
                FileClose($hSearch)
                Return 1 ; return 1 on success.
            EndIf
        Else
            Return SetError(0)
        
        FileClose($hSearch)
    EndIf

EndFunc ;==>Installing multiple printer on a machine

For a better forensic you should post the whole script ...

Greetz

Greenhorn

Edited by Greenhorn

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Here is the full code. I am still having problems with the red lines. I only need one of them but neither works. any help please i have racked my brain on this and still can not figure it out. Thanks in advance for all the help.

; GLOBAL OPTIONS
BlockInput(0)           ; 0 = Enable user input, 1 = Disable user input
Break(1)                ; 1 = Break is enabled (user can quit), 0 = Break is disabled (user cannot quit)
;RunAsSet('user', 'domain', 'pwd', 0); 0 = do not load the user profile, 1 = load the user profile, 2 = use for net credentials only
Opt('CaretCoordMode', 0)    ; 0 = relative coords to the active window, 1 = absolute screen coordinates, 2 = relative coords to the client area of the active window
Opt('ExpandEnvStrings', 0)  ; 0 = do not expand environment variables , 1 = expand environment variables
Opt('ExpandVarStrings', 0)  ; 0 = do not expand variables, 1 = expand variables (when in this mode and you want to use a literal $ or @ then double it up: "This is a single dollar $$ sign".
Opt('GUICloseOnESC', 1) ; 0 = Don't send the $GUI_EVENT_CLOSE message when ESC is pressed., 1 = Send the $GUI_EVENT_CLOSE message when ESC is pressed (default).
Opt('MouseCoordMode', 0)    ; 0 = relative coords to the active window, 1 = absolute screen coordinates, 2 = relative coords to the client area of the active window
Opt('MustDeclareVars', 0)      ; 0 = Variables don't need to be pre-declared, 1 = Variables must be pre-declared
Opt('PixelCoordMode', 0)    ; 0 = relative coords to the active window, 1 = absolute screen coordinates, 2 = relative coords to the client area of the active window
Opt('TrayIconDebug', 1)      ; 0 = no debug information, 1 = show debug
Opt('TrayIconHide', 0)           ; 0 = show icon, 1 = hide icon
Opt("WinTextMatchMode", 2)  ;1=complete, 2=quick
Opt("WinTitleMatchMode", 2);1=start, 2=subStr, 3=exact, 4=advanced

#region Variables

$Logs       =   @WindowsDir & '\Logs'               ; Installation log directory
$Path =     ''                      ; Path to application installation files

$Path1 =    'c:\pharos\'

$Server =   '\\***.***.***.***\monkey$'; UNC path to application server
$NetUser =  'Server\user'           ; Network account name
$NetPwd =   'password               ; Network account password
$NetForce   =   1                   ; Force network drive mapping with $Netuser and $NetPwd credentials
$NetDrive   =   0

$Target =   'CIS2028 CIS2030 CPR121 PCD2031 PHY209 PHY209B SCA216 SCA222 SOC279'; Partial hostname(s) to validate installation against
$Name =     'Pharos'                        ; Display name of application
$App =      'Pharos'                        ; Short name of application
$Ver =      '7.2'                       ; Application version

$client = StringSplit(@ComputerName, '-')

$CueTitle   =   $Name & ' ' & $Ver
$CueText    =   ''
#endregion Variables
#region Main

SplashTextOn($CueTitle, 'Lab: ' & $client[1], 500, 100, 15, 15, 4, "", 12)

NetDrive()

; >>> INSTALLATION <<<
If StringInStr($target, $client[1]) = 0 Then Quit ()
DirCreate($Path1)
DirCopy("\\131.247.98.6\apps$" & '\' & $App & '_' & $Ver & '\' & $Client[1] & '\', $Path1, 1)
TrayTip($client, $client[1], 10, 2)
sleep(5000)

Multiple ($Path1)

; >>> Installing multiple printer on a machine <<<

Func Multiple ($Path1)
    
    Local $hSearch, $Client, $CueText, $CueTitle, $PID, $EXE
    $hSearch = FileFindFirstFile($Path1 & '*.exe')
    If $hSearch = -1 Then
        Return SetError(0); returns 0
    Else
[color="#FF0000"];  $PID = RunWait($Path1 & $Client[1] & '*.exe')
        $PID = Run($Path1 & $Client[1] & '*.exe')[/color]
         If WinWait($Client, 'Install', 60) Then
            ClickOn($Client, 'Install', 'Button1', 100)
;~           Sleep(60000); 1 minute ?!
            ProcessWaitClose('PrnInstall.exe')
            If WinWaitActive($Client, 'Install', 60) Then
                ClickOn($Client, 'Install', 'Button2',100)
                Wait($PID)
                While 1
                    $EXE = FileFindNextFile($hSearch)
                    If @error Then ExitLoop
                    $CueText = ' Installing Printers ' & $EXE & ' ...'
                    ControlSetText($CueTitle, "",'Static1', @CRLF&$CueText)
                    TrayTip($CueTitle, $CueText, 10)
                    $iExitCode = RunWait($Path1 & $EXE)
                WEnd
                FileClose($hSearch)
                Return 1; return 1 on success.
            EndIf
        Else
            Return SetError(0)
        
        FileClose($hSearch)
    EndIf
    EndIf
EndFunc;==>Installing multiple printer on a machine

Quit()
#endregion Main
#region functions

DirCopy (

Func NetDrive()
;$CueText = '   Connecting to installation server...'
;ControlSetText($CueTitle, "", 'Static1', @CRLF&$CueText)
    TrayTip($CueTitle, $CueText, 10)
    $NetDrive = DriveGetDrive('NETWORK')
    If @error Then
        If $NetForce = 1 Then
            $Path = DriveMapAdd('*', $Server, 0, $NetUser, $NetPwd)
            Return
        Else
            $Path = DriveMapAdd('*', $Server)
            Return
        EndIf
        If $Path = 0 Then
            Select 
                Case @error = 1
                    MsgBox(4096, 'Error', 'Undefined Error - Exiting', 10)
                    Quit()
                Case @error = 2
                    MsgBox(4096, 'Error', 'Access to Server Denied - Exiting', 10)
                    Quit()
                Case @error = 3
                    MsgBox(4096, 'Error', 'All Drive Letters Assigned - Exiting', 10)
                    Quit()
                Case @error = 4
                    MsgBox(4096, 'Error', 'No Drive Letter Available - Exiting', 10)
                    Quit()
                Case @error = 5
                    MsgBox(4096, 'Error', 'Server Unavailable - Exiting', 10)
                    Quit()
                Case @error = 6
                    MsgBox(4096, 'Error', 'Username/Password Invalid - Exiting', 10)
                    Quit()
            EndSelect
        EndIf
    Else
        For $i = 1 to $NetDrive[0]
            $Map = DriveMapGet($NetDrive[$i])
            If $Map = $Server Then 
                $Path = $Map
                Return
            EndIf
        Next
        If $NetForce = 1 Then
            $Path = DriveMapAdd('*', $Server, 0, $NetUser, $NetPwd)
            Return
        Else
            $Path = DriveMapAdd('*', $Server)
            Return
        EndIf
    EndIf
EndFunc ;==>NetDrive

Func Wait($PID)
    While ProcessExists($PID)
        Sleep(1000)
    WEnd
EndFunc ;==>Wait

Func ClickOn($WinTitle, $WinText, $Button, $Sleep)
    If WinExists($WinTitle, $WinText) Then
        WinActivate($WinTitle, $WinText)
        ControlClick($WinTitle, $WinText, $Button)
        Sleep($Sleep)
    EndIf
EndFunc ;==>ClickOn


Func Quit()
    $CueText = '   Installation Complete'
    ControlSetText($CueTitle, "", 'Static1', @CRLF&$CueText)
    TrayTip($CueTitle, $CueText, 10)
    If DriveGetType($Path) = 'Network' Then DriveMapDel($Path)
    RunAsSet()
    BlockInput(0)
    SplashOff()
    Exit
EndFunc ;==>Quit
#endregion functions
Edited by Prego

Share this post


Link to post
Share on other sites

This line is wrong:

$PID = Run($Path1 & $Client[1] & '*.exe')

You can't have a wildcard in Run().

FileFindFirstFile() only returns a search handle. The actual name from the first found file is returned from FileFindNextFile().

Also you are trying to run all exe files in a folder but using the same routines for all of them.

ProcessWaitClose('PrnInstall.exe')

If WinWaitActive($Client, 'Install', 60) Then

This looks like it is only meant to run one program, why are you trying to run them all?

Share this post


Link to post
Share on other sites

I am trying to run multiple EXE files because some machines only get 1 printer installed and on ohter machine 2 or 3 printers get installed.

Share this post


Link to post
Share on other sites

I am trying to run multiple EXE files because some machines only get 1 printer installed and on ohter machine 2 or 3 printers get installed.

Your code doesn't appear to have a mechanism for determining which will have 1 printer and which will have 3.

You are better off installing printers silently rather than using window automation.

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