Sign in to follow this  
Followers 0
raviray

How to write command line in AUTOIT Script

9 posts in this topic

Hello -

I am new to AUTOIT Utility and using it first time to hide one window in which "Next" needs to be clicked so as to remove one application.

So basically I am working on removing one legacy setup.

Uninstall string to remove this applications is:

"C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml"

as far as I read I understood that two lines I need to write-

------

; Run uninstall.exe with complete command line (which I don't know how to do :(

Run ( "uninstall.exe" )

; Click on Next

WinWaitActive("ApplicationName Uninstaller", "click Next to continue")

Send("{ENTER}")

----

Please suggest how can I pass this uninstall command in Run.

--

Thanks & Regards,

Ravi

Share this post


Link to post
Share on other sites



Run ("C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml" )

Might suggest using ControlClick () for the buttons..its more reliable - look it up in the help file.


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

Run ("C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml" )

Might suggest using ControlClick () for the buttons..its more reliable - look it up in the help file.

Thanks for your response.

actually I am facing problem with executing/writing complete uninstall command using Run ().

If It would have been only exe which has to be executed I could have done that but there I have to run it as is given in "uninstall string" which I am unsure how to write in autoit.

I tried to write complete command line in batch file and then executing it thru this autoit utility but it didnt work.

--

Thanks

Ravi

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

; Run uninstall.exe with complete command line (which I don't know how to do

Try ShellExecute instead of Run. Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Try ShellExecute instead of Run.

Wether i use run or ShellExecute command problem with me is I dont know how to pass this whole string "C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml" in it.

if it would have been only till uninstall.exe i would have used

run("C:\WINDOWS\<Application name>\uninstall.exe")

'to suppress next tab which appear

WinWaitActive("ApplicationName Uninstaller", "click Next to continue")

Send("{ENTER}")

and it would have solved my problem.

but now here when after uninstall.exe this "/U:C:\<Application name>\irunin.xml" also need to be executed as is along with uninstall.exe(mentioned above)

Which I dont know how to write this whole string with passing arguments in Run or ShellExecute.

can someone write this single line for me and mention here.

Thank you

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

"C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml"

Hi Ravi,

You can just put single quotes around the whole string to enclose the double quotes.

Run('"C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml"')

The script below may help you until you get used to quoting. It will break the command in parts so you can replace for example, a path with a variable so it maybe easier and hopefully you will have little issue with quotes.

_Main()

Func _Main()
    Local $button_convert, $edit_input, $edit_output, $string
    GUICreate('CMD Line Converter', 520, 245)
    GUICtrlCreateLabel('CMD line string to convert into a suitable syntax for AutoIt3 which breaks the string down into parts', 10, 5)
    $edit_input = GUICtrlCreateEdit('', 10, 20, 500, 60)
    GUICtrlCreateLabel('Output', 10, 115)
    $edit_output = GUICtrlCreateEdit('', 10, 130, 500, 60)
    $button_convert = GUICtrlCreateButton('Con&vert', 130, 93, 260)
    $button_copy = GUICtrlCreateButton('&Copy', 130, 203, 260)
    GUISetState()
    While True
        Switch GUIGetMsg()
            Case -3
                GUIDelete()
                Exit
            Case $button_convert
                ; read the text in the input
                $string = GUICtrlRead($edit_input)
                $string = StringStripWS($string, 3); trim
                If $string Then
                    ; convert string and send text to output
                    _ConvertCLI($string)
                    GUICtrlSetData($edit_output, $string)
                EndIf
            Case $button_copy
                ; read the text from the output
                $string = GUICtrlRead($edit_output)
                If $string Then
                    ; send text from output to the clipboard
                    ClipPut($string)
                EndIf
        EndSwitch
    WEnd
EndFunc

Func _ConvertCLI(ByRef $string)
    Local $part
    ; replace certain items with tags
    $string = StringReplace($string, '"', '<SINGLE_ENCLOSE_DOUBLE>')
    $string = StringReplace($string, "'", '<DOUBLE_ENCLOSE_SINGLE>')
    $string = StringReplace($string, '&', '<CONCANTATION>')
    ; replace some tags here
    $string = _Tag_Replace($string, '<SINGLE_ENCLOSE_DOUBLE>', '&' & "'" & '"' & "'" & '&')
    $string = _Tag_Replace($string, '<DOUBLE_ENCLOSE_SINGLE>', '&"' & "'" & '"&')
    ; split string into parts and single quote parts if required
    $part = StringSplit($string, '&')
    For $i = 1 To UBound($part) -1
        ; nothing to change with these parts
        Switch $part[$i]
            Case '', '&', '<CONCANTATION>'
                ContinueLoop
        EndSwitch
        ; add single quotes to parts with no quotes
        If Not StringInStr($part[$i], '"') And Not StringInStr($part[$i], "'") Then
            $part[$i] = "'" & $part[$i] & "'"
        EndIf
    Next
    ; reuse $string to contain new string
    $string = ''
    ; join string parts into a whole string
    For $i = 1 To UBound($part) -1
        Switch $part[$i]
            ; do not include these parts
            Case '', "''"
                ContinueLoop
        EndSwitch
        $string &= $part[$i] & ' & '
    Next
    $string = StringTrimRight($string, 3)
    ; merge single quoted whitespace with nearest parts of the whole string
    $string = StringReplace($string, "'" & ' & ' & "' '" & ' & ' & "'", ' ')
    ; replace some tags here
    $string = _Tag_Replace($string, '<CONCANTATION>', '&')
    Return $string
EndFunc

Func _Tag_Replace($string, $tag, $replacement_string)
    ; replace tags with replacement string
    $string = StringReplace($string, $tag, $replacement_string)
    ; replacement strings need to be trimmed if on either end of the string
    If StringRight($string, 1) = '&' Then
        $string = StringTrimRight($string, 1)
    EndIf
    If StringLeft($string, 1) = '&' Then
        $string = StringTrimLeft($string, 1)
    EndIf
    Return $string
EndFunc

Paste command line into top edit control, press convert to get result into bottom edit control. Press copy button to add to clipboard. :(

Edit:

Just noticed that perhaps a double quote is in the incorrect position.

Also try

Run('"C:\WINDOWS\<Application name>\uninstall.exe" /U:"C:\<Application name>\irunin.xml"')

The double quote is after the full colon above.

Edited by MHz

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

As you suggested - It worked.

Run('"C:\WINDOWS\<Application name>\uninstall.exe" "/U:C:\<Application name>\irunin.xml"')

Thank you So much!!!

Your help is highly appreciated..I am so happy,it worked.

Edited by raviray

Share this post


Link to post
Share on other sites

I didn't found any TAB to mention "resolved"/"solved" for my post...like usually we have to selece as completed.

nyways

Thank you again.

Share this post


Link to post
Share on other sites

You have to edit first post and change title. I don't know if you have enough total post count to do that though.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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