Jump to content

Autoit syntax help


Recommended Posts

I recently started using WPKG and have been trying to write a script in autoit to distribute through it. The script should run an installer via the command line, close a window that opens, then start the service associated with that install. It runs through the script without any failures but it's not actually executing the install on the command line. This has been driving me crazy and any help would be appreciated.

MsgBox(0, "Notice", "Line 2")
Run(@ComSpec & "/c" & '"C:\Program Files\nsclient\pNSClient.exe" /install', "", @SW_HIDE)
Sleep(2000)
MsgBox(0, "Notice", "Line 5")
If WinExists("Information") Then
WinActivate("Information")
Else
WinActivate("Error")
EndIf
Send("{ENTER}")
Sleep(500)
Run(@ComSpec & "/c" & 'NET START "NetSaint NT Agent"', "", @SW_HIDE)
MsgBox(0, "Notice", "Service Started")

The message boxes are just for error checking.

Link to comment
Share on other sites


Ahhhhh, thank you so much. I can't believe I overlooked that. It makes so much sense. Everything worked beautifully. What would be the format for this line then if I wanted to use @ProgramFilesDir instead of a static path? I tried:

Run(@ComSpec & " /c " & @ProgramFilesDir & '"\nsclient\pNSClient.exe" /install', "", @SW_HIDE)

...but it came up with a parsing error during run time.

Thanks again.

Link to comment
Share on other sites

Run(@ComSpec & " /c " & @ProgramFilesDir & '"\nsclient\pNSClient.exe" /install', "", @SW_HIDE)

...but it came up with a parsing error during run time.

Yeah, you have a double quote in a bad place. Good practice to add a Msgbox prior to the function call with the command string in it to debug issues in the syntax.

Your command string would evaluate to be

C:\Windows\System32\cmd.exe /c C:\Program Files"\nsclient\pNSClient.exe" /install

Some changes I made but the your lines of concern should be resolved.


MsgBox(0, "Notice", "Line 2")
; run pNSClient.exe installation
Run('"' & @ComSpec & '" /c "' & @ProgramFilesDir & '\nsclient\pNSClient.exe" /install', "", @SW_HIDE)
; call function every 250ms to check for error title
AdlibEnable('_Error_check')
Sleep(2000)
MsgBox(0, "Notice", "Line 5")
; wait for Information title
If WinWait("Information", "", 10) Then
While Not WinActive("Information")
; activate the Information title
WinActivate("Information")
Sleep(500)
If Not WinExists("Information") Then
; quit the loop if title does not exist
ExitLoop
EndIf
WEnd
; progress if the title is active
WinWaitActive("Information")
Send("{ENTER}")
EndIf
Sleep(500)
; start a service
Run('"' & @ComSpec & '" /c NET START "NetSaint NT Agent"', "", @SW_HIDE)
MsgBox(0, "Notice", "Service Started")

Exit

Func _Error_check()
If WinExists('Error') Then
WinActivate('Error')
If WinActive('Error') Then
Send('{ENTER}')
EndIf
EndIf
EndFunc

Just changed to make use of AdlibEnable to handle the error window and other minor changes.

:)

Edited by MHz
Link to comment
Share on other sites

Thanks MHz. I just started using Autoit and the syntax is killing me compared to all other programming languages. I wasn't familiar with the Adlib functions. They seem really useful after seeing your example.

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...