Jump to content
Sign in to follow this  
Traveler

How to hide CMD command window when running Autoit

Recommended Posts

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}")

Share this post


Link to post
Share on other sites

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 by javasqlrpg

Share this post


Link to post
Share on other sites

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 2020-07-21 - Version 1.5.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 2020-07-21 - Version 1.5.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 by javasqlrpg

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...