mihaijulien Posted June 19, 2017 Share Posted June 19, 2017 Hello, I need to automate the install process of an application. Everything works fine when using the default configuration. But there's a problem when changing the default install location. I have the following code: expandcollapse popup#requireadmin #include <FileConstants.au3> #include <WinApi.au3> Opt("WinTitleMatchMode",2) Global $defaultLocation = "C:\Program Files\MyApp" Global $alternateLocation = "D:\MyApp" InstallG2() Func InstallG2() Local $hWnd = "Install Wizard" Local $dir = DirCreate($alternateLocation) ;create alternate location folder ShellExecute("win-installer-5.6.0.msi","",@ScriptDir & "\c2") While Not ControlCommand($hWnd,"","[Text:&Next >]", "IsEnabled",'') Sleep(500) WEnd ;if the app is already installed, close the install wizard If ControlGetText($hWnd,"","[Text:Remove Installation]") Then WinClose($hWnd) Return Else ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ;first Next ;1572 Local $counter = 0 For $counter = 0 to 1 Send("{TAB}") Sleep(100) Next Send("{UP}") ;accept the terms in the License Agreement ;57 Sleep(100) ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ; Next ;1572 Sleep(500) ControlClick($hWnd,"","[CLASS:Button; INSTANCE:5]") ; uncheck start Sleep(500) ;install in a different location _selectEdit($hWnd) ControlSetText($hWnd,$defaultLocation,"[CLASS:Edit; INSTANCE:1]", $alternateLocation) Sleep(1000) ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ; Next ;1572 If ControlGetText("Error","","[CLASS:Button; INSTANCE:1]") Then Exit EndIf ; wait the install successful UI While 1 $var = ControlGetText($hWnd, "", "[Text:&Finish]") If $var == "&Finish" Then ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ;Finish ExitLoop EndIf Sleep(1000) WEnd EndIf EndFunc ; select the edit text box when changing the install location Func _selectEdit($hWnd) $hWnd = _WinAPI_GetFocus() $class = _WinAPI_GetClassName($hWnd) If $class = 'Edit' Then _GUICtrlEdit_SetSel($hWnd, 0, -1) EndFunc The above code doesn't work, when the installing process reaches the step for choosing the install location, it throws an error "Path already exists". If I comment this line: ;Local $dir = DirCreate($alternateLocation) then the app installs in the default location, even though I change the install location. Any ideas what could be wrong or any workaround? Link to comment Share on other sites More sharing options...
mihaijulien Posted June 19, 2017 Author Share Posted June 19, 2017 (edited) So, I am stopping the script after it sends the alternate location to the edit box and from that point I continue the installation manually. expandcollapse popup#requireadmin #include <FileConstants.au3> #include <WinApi.au3> Opt("WinTitleMatchMode",2) Global $defaultLocation = "C:\Program Files\MyApp" Global $alternateLocation = "D:\MyApp" InstallG2() Func InstallG2() Local $hWnd = "Install Wizard" Local $dir = DirCreate($alternateLocation) ;create alternate location folder ShellExecute("win-installer-5.6.0.msi","",@ScriptDir & "\c2") While Not ControlCommand($hWnd,"","[Text:&Next >]", "IsEnabled",'') Sleep(500) WEnd ;if the app is already installed, close the install wizard If ControlGetText($hWnd,"","[Text:Remove Installation]") Then WinClose($hWnd) Return Else ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ;first Next ;1572 Local $counter = 0 For $counter = 0 to 1 Send("{TAB}") Sleep(100) Next Send("{UP}") ;accept the terms in the License Agreement ;57 Sleep(100) ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") ; Next ;1572 Sleep(500) ControlClick($hWnd,"","[CLASS:Button; INSTANCE:5]") ; uncheck start Sleep(500) ;install in a different location _selectEdit($hWnd) ControlSetText($hWnd,$defaultLocation,"[CLASS:Edit; INSTANCE:1]", $alternateLocation) Sleep(100000000) ; <----------- I stop the script here EndFunc The result is the same, the app install in the default location at C:\Program Files\MyApp. That's pretty strange. Edited June 19, 2017 by mihaijulien Link to comment Share on other sites More sharing options...
mihaijulien Posted June 19, 2017 Author Share Posted June 19, 2017 (edited) Ok, so I found a workaround. Instead of: ControlSetText($hWnd,$defaultLocation,"[CLASS:Edit; INSTANCE:1]", $alternateLocation) I used: Send("D:\MyApp") Edited June 19, 2017 by mihaijulien Link to comment Share on other sites More sharing options...
Subz Posted June 19, 2017 Share Posted June 19, 2017 Why not use the msi properties for example: Global $alternateLocation = "D:\MyApp" RunWait('MsiExec.exe /i "' & @ScriptDir & '\c2\win-installer-5.6.0.msi" /QB InstallDir="' & $alternateLocation & '" /NoRestart') mihaijulien 1 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