zone97 Posted April 12, 2008 Share Posted April 12, 2008 Being as I am new to using this application, here is what i am trying to accomplish. I have 3 programs that need to be launched in order. If any of them fail, they all must be downed, and restarted. Here is what I have, it works but I would like to have someone else look and see if I should/could be doing this a better way. Later on, i will be adding other fucntions where as one of the programs being ran, has to have some login information passed to it. In the example below I am using 3 standard window applications for testing. expandcollapse popup#NoTrayIcon #include <GuiConstants.au3> #include <Constants.au3> #AutoIt3Wrapper_icon=template.ico Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("WinWaitDelay", 750) $progm1 = IniRead("template.ini","program1","progm","") $progm2 = IniRead("template.ini","program2","progm","") $progm3 = IniRead("template.ini","program3","progm","") $title1 = IniRead("template.ini","program1","title","") $title2 = IniRead("template.ini","program2","title","") $title3 = IniRead("template.ini","program3","title","") TraySetIcon("Shell32.dll", -134) ;GUISetIcon("Shell32.dll",-134) <-- No longer needed TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent") ;TraySetState(2) ; hide --> not needed GUICreate("Template", 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("&Help") $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu) GUISetState() GUICtrlCreateLabel("Loading...", 100, 60) $i = 0 $x = 0 While 1 $msg = GUIGetMsg() ; this is where the program starts. if $x = 0 then startpgms() if $x = 1 then checkpgms() ;GUICtrlCreateLabel("...Done...", 100, 60) ; this is where the program ends. Select Case $msg = $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) TraySetState(1) ; show TrayTip("", "blank tooltip", 0) ; blank tooltip! Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem ExitLoop Case $msg = $aboutitem MsgBox(0, "About", "This is the about dialog box.") EndSelect WEnd Func SpecialEvent() GUISetState(@SW_SHOW) TraySetState(2) ; hide EndFunc ;==>SpecialEvent Func startpgms() if ProcessExists($progm1) Then Else For $i = 1 to 5000000 Next Run($progm1) WinWait($title1,"",10) EndIf if ProcessExists($progm2) Then Else For $i = 1 to 5000000 Next Run($progm2) WinWait($title2,"",10) EndIf if ProcessExists($progm3) Then Else For $i = 1 to 5000000 Next Run($progm3) WinWait($title3,"",10) EndIf $x = 1 EndFunc Func checkpgms() if ProcessExists($progm1) Then Else ProcessClose($progm2) ProcessClose($progm3) $x = 0 EndIf if ProcessExists($progm2) Then Else ProcessClose($progm1) ProcessClose($progm3) $x = 0 EndIf if ProcessExists($progm3) Then Else ProcessClose($progm1) ProcessClose($progm2) $x = 0 EndIf EndFunc here is the ini file.. [program1] progm=calc.exe title=Calculator [program2] progm=notepad.exe title=Untitled - Notepad [program3] progm=mspaint.exe title=untitled - Paint Thanks. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
martin Posted April 12, 2008 Share Posted April 12, 2008 Being as I am new to using this application, here is what i am trying to accomplish. I have 3 programs that need to be launched in order. If any of them fail, they all must be downed, and restarted. Here is what I have, it works but I would like to have someone else look and see if I should/could be doing this a better way. Later on, i will be adding other fucntions where as one of the programs being ran, has to have some login information passed to it. In the example below I am using 3 standard window applications for testing. expandcollapse popup#NoTrayIcon #include <GuiConstants.au3> #include <Constants.au3> #AutoIt3Wrapper_icon=template.ico Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("WinWaitDelay", 750) $progm1 = IniRead("template.ini","program1","progm","") $progm2 = IniRead("template.ini","program2","progm","") $progm3 = IniRead("template.ini","program3","progm","") $title1 = IniRead("template.ini","program1","title","") $title2 = IniRead("template.ini","program2","title","") $title3 = IniRead("template.ini","program3","title","") TraySetIcon("Shell32.dll", -134) ;GUISetIcon("Shell32.dll",-134) <-- No longer needed TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent") ;TraySetState(2) ; hide --> not needed GUICreate("Template", 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("&Help") $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu) GUISetState() GUICtrlCreateLabel("Loading...", 100, 60) $i = 0 $x = 0 While 1 $msg = GUIGetMsg() ; this is where the program starts. if $x = 0 then startpgms() if $x = 1 then checkpgms() ;GUICtrlCreateLabel("...Done...", 100, 60) ; this is where the program ends. Select Case $msg = $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) TraySetState(1) ; show TrayTip("", "blank tooltip", 0) ; blank tooltip! Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem ExitLoop Case $msg = $aboutitem MsgBox(0, "About", "This is the about dialog box.") EndSelect WEnd Func SpecialEvent() GUISetState(@SW_SHOW) TraySetState(2) ; hide EndFunc ;==>SpecialEvent Func startpgms() if ProcessExists($progm1) Then Else For $i = 1 to 5000000 Next Run($progm1) WinWait($title1,"",10) EndIf if ProcessExists($progm2) Then Else For $i = 1 to 5000000 Next Run($progm2) WinWait($title2,"",10) EndIf if ProcessExists($progm3) Then Else For $i = 1 to 5000000 Next Run($progm3) WinWait($title3,"",10) EndIf $x = 1 EndFunc Func checkpgms() if ProcessExists($progm1) Then Else ProcessClose($progm2) ProcessClose($progm3) $x = 0 EndIf if ProcessExists($progm2) Then Else ProcessClose($progm1) ProcessClose($progm3) $x = 0 EndIf if ProcessExists($progm3) Then Else ProcessClose($progm1) ProcessClose($progm2) $x = 0 EndIf EndFunc here is the ini file.. [program1] progm=calc.exe title=Calculator [program2] progm=notepad.exe title=Untitled - Notepad [program3] progm=mspaint.exe title=untitled - Paint Thanks. Looks ok to me. I'm not sure about the for/next which seems to be for a delay so you could have used Sleep, but I'm not sure why you need delays there. Also, instead of if else you can use if not if ProcessExists($progm1) then else msgox(0,.. endif [code] is the same as [code] if not ProcessExists($progm1) then msgbox(0,... endif I like to use arrays if it means I don't have to keep writing the same thing again; it speeds up writing a script sometimes and makes debugging simpler. Also anything which isn't really needed can be removed. So I would do something like this. (This is just written without testing.) expandcollapse popup#NoTrayIcon #include <GuiConstants.au3> #include <Constants.au3> #AutoIt3Wrapper_icon=template.ico Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("WinWaitDelay", 750) Dim $program[3], $title[3] For $loop = 1 To 3 $progm[$loop] = IniRead("template.ini", "program" & $loop, "progm", "") $title[$loop] = IniRead("template.ini", "program" & $loop, "title", "") Next TraySetIcon("Shell32.dll", -134) ;GUISetIcon("Shell32.dll",-134) <-- No longer needed TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent") ;TraySetState(2); hide --> not needed GUICreate("Template", 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("&Help") $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu) GUISetState() GUICtrlCreateLabel("Loading...", 100, 60) While 1 $msg = GUIGetMsg() ; this is where the program starts. checkpgms ();since this followed startpgms migh as well have one fn here ;and call startpgms from checkpgms if needed ;GUICtrlCreateLabel("...Done...", 100, 60) ; this is where the program ends. Select Case $msg = $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) TraySetState(1); show TrayTip("", "blank tooltip", 0); blank tooltip! Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem ExitLoop Case $msg = $aboutitem MsgBox(0, "About", "This is the about dialog box.") EndSelect WEnd Func SpecialEvent() GUISetState(@SW_SHOW) TraySetState(2); hide EndFunc ;==>SpecialEvent Func startpgms() ;start all programs ;no need to check if they actually run because checkpgs does that anyway. Local $nn, For $nn = 1 To 3 If Not ProcessExists($progm[$nn]) Then Run($progm1) EndIf Next EndFunc ;==>startpgms Func checkpgms () Local $nn, $halt = False For $nn = 1 To 3 If Not ProcessExists($progm[$nn]) Then $halt = True ExitLoop EndIf Next If $halt Then For $nn = 1 To 3 If ProcessExists($progm[$nn]) Then ProcessClose($program[$nn]) Next startpgms() EndIf EndFunc ;==>checkpgms Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
zone97 Posted April 12, 2008 Author Share Posted April 12, 2008 (edited) Looks ok to me. I'm not sure about the for/next which seems to be for a delay so you could have used Sleep, but I'm not sure why you need delays there. Also, instead of if else you can use if not I applied some of the tips you offered, however I had to do the following. Dim $progm[4], $title[4], $loop For $loop = 1 To 3 with out making the array [4] it would report array exceeded? Didnt make sense to me... Unless the array was assuming $progm[0] existed? instead of just 1-2-3 ect..? Edited April 12, 2008 by zone97 Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
martin Posted April 12, 2008 Share Posted April 12, 2008 (edited) I applied some of the tips you offered, however I had to do the following. Dim $progm[4], $title[4], $loop For $loop = 1 To 3 with out making the array [4] it would report array exceeded? Didnt make sense to me... Unless the array was assuming $progm[0] existed? instead of just 1-2-3 ect..? Sorry, even though I didn't test it I should not have made a mistake like that. You are right, you need to declare with 4 elements for my example to work because Dim $a[3] means that $a has 3 elements $a[0], $a[1] and $a[2] and there is no $a[3]. Or instead I could have said $progm[$nn - 1] inside the for/next loops. Ah well, you can learn from other people's mistakes as well as your own. Edited April 12, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now