Sign in to follow this  
Followers 0
Traveler

How to hide CMD command window when running Autoit

7 posts in this topic

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



#2 ·  Posted (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 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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by javasqlrpg

Share this post


Link to post
Share on other sites

Hello All

Thank you very much for your quick support. This works 100%. Just what I were looking for.

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  
Followers 0