copyleft Posted December 1, 2020 Share Posted December 1, 2020 I want the script to exit, after the second message box command (which is invoked if there is no network connection), whether or not the user presses the OK button before the 10 second message box time out. Right now, the script continues, sequentially, instead of going to "Exit" at the end. #RequireAdmin #include <FileConstants.au3> #include <MsgBoxConstants.au3> $RemDir = "\\Network\HomeDir" $process = "Outlook.exe" $LogFile = FileOpen("M:\NAS\Log\SYNC2NAS\Sync.log", 1) Local $var = Ping("XX.XX.XX.90", 4000) If $var Then ;double line message box MsgBox(64, "Backup", "CONNECTION EXISTS. . ." & @LF & "Starting backup to NAS in 4 seconds..." & @LF & @LF &$RemDir, 4) Else MsgBox(0, "Network status", "Unable to connect..", 10) EndIf If ProcessExists($process) Then ProcessClose($process) sleep(1000) RUNWAIT ("RunCopyProgram.exe") Else RUNWAIT ("RunCopyProgram.exe") FileWriteLine($LogFile, "Selected program directories successfully backed up on: >>> " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & @CRLF) FileClose($LogFile) MsgBox(48, "Sync", "Selected program directories have been backed up" & @LF & "This box will close in three seconds . .", 3) EndIf Exit Link to comment Share on other sites More sharing options...
boom221 Posted December 1, 2020 Share Posted December 1, 2020 I would add an Exit right under the msgbox line? Link to comment Share on other sites More sharing options...
copyleft Posted December 1, 2020 Author Share Posted December 1, 2020 (edited) If I do that, the script exits regardless of whether there is a network connection or not. I only want to exit if there is not a network connection. Sorry didn't follow your instructions fully. I put it right under message box line as you said. It now works. Thanks a lot. Edited December 1, 2020 by copyleft Link to comment Share on other sites More sharing options...
pseakins Posted December 1, 2020 Share Posted December 1, 2020 (edited) If $var Then ;double line message box MsgBox(64, "Backup", "CONNECTION EXISTS. . ." & @LF & "Starting backup to NAS in 4 seconds..." & @LF & @LF &$RemDir, 4) Else MsgBox(0, "Network status", "Unable to connect..", 10) FileClose($LogFile) Exit EndIf Edited December 1, 2020 by pseakins added file close Phil Seakins Link to comment Share on other sites More sharing options...
copyleft Posted December 2, 2020 Author Share Posted December 2, 2020 @pseakins. Thanks. Link to comment Share on other sites More sharing options...
Exit Posted December 2, 2020 Share Posted December 2, 2020 Just a shorter version: #RequireAdmin $process = "Outlook.exe" If Not Ping("XX.XX.XX.90", 4000) Then Exit MsgBox(0, "Network status", "Unable to connect..", 10) MsgBox(64, "Backup", "CONNECTION EXISTS. . ." & @LF & "Starting backup to NAS in 4 seconds..." & @LF & @LF & "\\Network\HomeDir", 4) If ProcessExists($process) Then Sleep(1000 * ProcessClose($process)) RunWait("RunCopyProgram.exe") $LogFile = FileOpen("M:\NAS\Log\SYNC2NAS\Sync.log", 1) FileWriteLine($LogFile, "Selected program directories successfully backed up on: >>> " & @MDAY & "/" & @MON & " " & @HOUR & ":" & @MIN & @CRLF) FileClose($LogFile) MsgBox(48, "Sync", "Selected program directories have been backed up" & @LF & "This box will close in three seconds . .", 3) App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
copyleft Posted December 2, 2020 Author Share Posted December 2, 2020 I'm learning a lot here.... @Exit. What's the function of the asterisk after sleep in line 5? Link to comment Share on other sites More sharing options...
GokAy Posted December 2, 2020 Share Posted December 2, 2020 (edited) It is multiplication, if processclose is un-successful= 0 then sleep (1000 x 0), if 1 then sleep(1000 x 1) or vice-versa, have to check function page. Edit: In bold Edited December 2, 2020 by GokAy typo Link to comment Share on other sites More sharing options...
Musashi Posted December 2, 2020 Share Posted December 2, 2020 14 minutes ago, copyleft said: What's the function of the asterisk after sleep in line 5? if ProcessExists($process) Then Sleep(1000 * ProcessClose($process)) This is just another notation for : If ProcessExists($process) Then ProcessClose($process) sleep(1000) ProcessClose returns 1 (=Success) or 0 (=Failure). The Sleep therefore has a duration of 1000 times 1 or 1000 times 0 milliseconds. ==> there is only a Sleep if the Process exists. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
copyleft Posted December 2, 2020 Author Share Posted December 2, 2020 @GokAy & @Musashi Thanks for the explanation. Link to comment Share on other sites More sharing options...
pseakins Posted December 2, 2020 Share Posted December 2, 2020 6 hours ago, Musashi said: ==> there is only a Sleep if the Process exists. What if the process exists but the ProcessClose() fails? With @exit's code there is only a sleep if the process exists and it is successfully closed. Plus, statements like this are cool. Phil Seakins Link to comment Share on other sites More sharing options...
GokAy Posted December 2, 2020 Share Posted December 2, 2020 @pseakins You could use bitwise operations perhaps? BitOr(ProcessExists($process),ProcessClose($process)) BitAnd(ProcessExists($process),ProcessClose($process)) Idk, which one (or some other operation) would return what you want though as I have not followed the thread. Link to comment Share on other sites More sharing options...
JockoDundee Posted December 2, 2020 Share Posted December 2, 2020 1 hour ago, pseakins said: What if the process exists but the ProcessClose() fails? With @exit's code there is only a sleep if the process exists and it is successfully closed. Plus, statements like this are cool. Might as well skip the if altogether and just say: Sleep(1000 * ProcessClose($process)) Exit 1 Code hard, but don’t hard code... 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