Traveler Posted November 15, 2011 Share Posted November 15, 2011 Hi I'm pretty new to this, and have a couple of questions, I hope you can answer. I have created this small program - it runs :-) So far so good. But I would like the program to be started, and then run in the background, so the user do not see the CMD commands entered. Any idea how to do this ? Also, if I want to check if each step is successfull before proceeding to the next command, then how to do this ? Here's the program: $answer = MsgBox(4, "AutoIt Example (English Only)", "Updating system clock.Do you want to proceed ?") If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Good bye !") Exit EndIf run ("cmd") send("cnet stop w32time{ENTER}") sleep (5000) send("net time /setsntp:time.windows.com{ENTER}") sleep (5000) send("net start w32time{ENTER}") sleep (5000) send("exit{ENTER}") Link to comment Share on other sites More sharing options...
javasqlrpg Posted November 15, 2011 Share Posted November 15, 2011 (edited) no need to use run and send. runwait will also wait for the command to finish , so i think you can exclude the sleep(5000) and you are left with RunWait(@ComSpec & ' /c ' & "net stop w32time", @TempDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & "net time /setsntp:time.windows.com", @TempDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & "net start w32time", @TempDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & "net stop w32time", @TempDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & "net time /setsntp:time.windows.com", @TempDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & "net start w32time", @TempDir, @SW_HIDE) Edited November 15, 2011 by javasqlrpg Link to comment Share on other sites More sharing options...
water Posted November 15, 2011 Share Posted November 15, 2011 Remove the surplus bracket and you are done. RunWait(@ComSpec & ' /c ' & "cnet stop w32time", @TempDir, @SW_HIDE) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Traveler Posted November 15, 2011 Author Share Posted November 15, 2011 Hi Thank you very much :-) This works ! Is there any way, to tell the user, that the update ran OK when it is finish ? Thanks. Link to comment Share on other sites More sharing options...
water Posted November 15, 2011 Share Posted November 15, 2011 Please check the help file for RunWait: Success: Returns the exit code of the program that was run. $iResult = RunWait(...) Depending on the program you run $iResult contains the exit code of the called program. I would suggest you try a successfull and and unsuccessfull command and check if $iResult has a different value. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
javasqlrpg Posted November 16, 2011 Share Posted November 16, 2011 (edited) The Help file and examples is a great way to learn. but to put incode what water said : $iResult = RunWait(@ComSpec & ' /c ' & "net stop w32time", @TempDir, @SW_HIDE) If $iResult = 1 Then MsgBox(16, "error", "Error Stopping time") Exit EndIf $iResult = RunWait(@ComSpec & ' /c ' & "net time /setsntp:time.windows.com", @TempDir, @SW_HIDE) If $iResult = 1 Then MsgBox(16, "error", "Error setting time") Exit EndIf $iResult = RunWait(@ComSpec & ' /c ' & "net start w32time", @TempDir, @SW_HIDE) If $iResult = 1 Then MsgBox(16, "error", "Error starting time") Exit Else MsgBox(0, "Success", "Completed") EndIf Edited November 16, 2011 by javasqlrpg Link to comment Share on other sites More sharing options...
Traveler Posted November 16, 2011 Author Share Posted November 16, 2011 Hello All Thank you very much for your quick support. This works 100%. Just what I were looking for. 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