Jump to content

Recommended Posts

Posted

Hi There,

I'm looking to see if there is a way to run multiple RunWait's at the same time, so I can start multiple services at the same time and wait for them all to complete before continuing the script.

Here is my script I was working on last night. Unfortunately, today I realize my attempt achieve this goal didn't pan out as I originally thought. Any thoughts?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         CHRONOMASTER

 Script For:
    VMware Workstation 6.5.2
    
 Script Function:
    Load VMware and Unload when closed.

#ce ----------------------------------------------------------------------------

; Hide tray icon.
Opt ( "TrayIconHide", 1 )

; Set your VMware Workstation install path here.
$InstallPath = "D:\Program Files\VMware\VMware Workstation\"

Func StartServices ( )
    Run ( @comspec & ' /c net start "VMware Authorization Service"', "", @SW_HIDE )
    Run ( @comspec & ' /c net start "VMware DHCP Service"', "", @SW_HIDE )
    Run ( @comspec & ' /c net start "VMware NAT Service"', "", @SW_HIDE )
EndFunc

; Start Services, Tray and Program.
RunWait ( StartServices ( ) )  ; <---- Last night I was hopping this would work, but it just waits the the function to complete not the programs.
Run ( $InstallPath & "vmware-tray.exe" )
Run ( $InstallPath & "vmware.exe" )

; Wait to close Services and Tray until VMware Workstation is closed.
Do
    Sleep ( 20000 ) ; Wait for 20 seconds.
    $WinState = ProcessExists ( "vmware.exe" )
    If $WinState = 0 Then
        ProcessClose ( "vmware-tray.exe" )
        Run ( @comspec & ' /c net stop "VMware Authorization Service"', "", @SW_HIDE )
        Run ( @comspec & ' /c net stop "VMware DHCP Service"', "", @SW_HIDE )
        Run ( @comspec & ' /c net stop "VMware NAT Service"', "", @SW_HIDE )
    EndIf
Until $WinState = 0

; Exit Script when done.
Exit
Posted (edited)

  On 7/12/2009 at 9:45 PM, 'herewasplato said:

Take a look at

Thanks for the replay, but after doing some reading it only seems to deal with running your script as a service and not having your script start/stop multiple services at the same time (or close too) and wait for them all to complete. Edited by CHRONOMASTER
Posted (edited)

  On 7/12/2009 at 10:04 PM, 'CHRONOMASTER said:

Thanks for the replay, but after doing some reading it only seems to deal with running your script as a service and not having your script start/stop multiple services at the same time (or close too) and wait for them all to complete.

Maybe I was thinking of this post instead:

#551877

As far as running at the same time - you might have to launch a child script for each - I've not thought that part thru.

You might want to look at this layout instead of your ending do/until loop:

Run($InstallPath & "vmware-tray.exe")
Run($InstallPath & "vmware.exe")

ProcessWait("vmware.exe")
ProcessWaitClose("vmware.exe")
ProcessClose("vmware-tray.exe")
Run(@ComSpec & ' /c net stop "VMware Authorization Service"', "", @SW_HIDE)
Run(@ComSpec & ' /c net stop "VMware DHCP Service"', "", @SW_HIDE)
Run(@ComSpec & ' /c net stop "VMware NAT Service"', "", @SW_HIDE)

Edit: Doh! Welcome to the forum :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

I applied your suggestion and I was able to figure out my problem, I captured the PID of each Run and did a delayed Do/Until loop until all three PID's equaled zero. Problem solved, and Thank you for the help!

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         CHRONOMASTER

 Script For:
    VMware Workstation 6.5.2
    
 Script Function:
    Load VMware and Unload when closed.

#ce ----------------------------------------------------------------------------

; Hide tray icon.
Opt ( "TrayIconHide", 1 )

; Set your VMware Workstation install path here.
$InstallPath = "D:\Program Files\VMware\VMware Workstation\"

Func StartServices ( )
    $PID1 = Run ( @comspec & ' /c net start "VMware Authorization Service"', "", @SW_HIDE )
    $PID2 = Run ( @comspec & ' /c net start "VMware DHCP Service"', "", @SW_HIDE )
    $PID3 = Run ( @comspec & ' /c net start "VMware NAT Service"', "", @SW_HIDE )
    Do
        Sleep ( 250 )
        $PID1 = ProcessExists ( $PID1 )
        $PID2 = ProcessExists ( $PID2 )
        $PID3 = ProcessExists ( $PID3 )
    Until $PID1 = 0 AND $PID2 = 0 AND $PID3 = 0
EndFunc

; Start Services, Tray and Program.
Run ( StartServices ( ) )
Run ( $InstallPath & "vmware-tray.exe" )
Run ( $InstallPath & "vmware.exe" )

; Wait to close Services and Tray until VMware Workstation is closed.
ProcessWait ( "vmware.exe" )
ProcessWaitClose ( "vmware.exe" )
ProcessClose ( "vmware-tray.exe" )
Run ( @ComSpec & ' /c net stop "VMware Authorization Service"', "", @SW_HIDE )
Run ( @ComSpec & ' /c net stop "VMware DHCP Service"', "", @SW_HIDE )
Run ( @ComSpec & ' /c net stop "VMware NAT Service"', "", @SW_HIDE )

; Exit Script when done.
Exit
Posted

  On 7/13/2009 at 3:37 AM, 'CHRONOMASTER said:

... Problem solved, and Thank you for the help! ...

Good solution... and you are welcome.

You really do not need @ComSpec

Net will run fine by itself :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted (edited)

  On 7/13/2009 at 3:37 AM, 'CHRONOMASTER said:

I applied your suggestion and I was able to figure out my problem, I captured the PID of each Run and did a delayed Do/Until loop until all three PID's equaled zero. Problem solved, and Thank you for the help!

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         CHRONOMASTER

 Script For:
    VMware Workstation 6.5.2
    
 Script Function:
    Load VMware and Unload when closed.

#ce ----------------------------------------------------------------------------

; Hide tray icon.
Opt ( "TrayIconHide", 1 )

; Set your VMware Workstation install path here.
$InstallPath = "D:\Program Files\VMware\VMware Workstation\"

Func StartServices ( )
    $PID1 = Run ( @comspec & ' /c net start "VMware Authorization Service"', "", @SW_HIDE )
    $PID2 = Run ( @comspec & ' /c net start "VMware DHCP Service"', "", @SW_HIDE )
    $PID3 = Run ( @comspec & ' /c net start "VMware NAT Service"', "", @SW_HIDE )
    Do
        Sleep ( 250 )
        $PID1 = ProcessExists ( $PID1 )
        $PID2 = ProcessExists ( $PID2 )
        $PID3 = ProcessExists ( $PID3 )
    Until $PID1 = 0 AND $PID2 = 0 AND $PID3 = 0
EndFunc

; Start Services, Tray and Program.
Run ( StartServices ( ) )
Run ( $InstallPath & "vmware-tray.exe" )
Run ( $InstallPath & "vmware.exe" )

; Wait to close Services and Tray until VMware Workstation is closed.
ProcessWait ( "vmware.exe" )
ProcessWaitClose ( "vmware.exe" )
ProcessClose ( "vmware-tray.exe" )
Run ( @ComSpec & ' /c net stop "VMware Authorization Service"', "", @SW_HIDE )
Run ( @ComSpec & ' /c net stop "VMware DHCP Service"', "", @SW_HIDE )
Run ( @ComSpec & ' /c net stop "VMware NAT Service"', "", @SW_HIDE )

; Exit Script when done.
Exit

Hi,

because of the dependencies between the VM Ware services you should use RunWait instead of Run in function StartServices.

;-)

Stefan

Edited by 99ojo

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...