truejegor
Posts: 7
Joined: Thu Sep 16, 2021 9:49 am

Сompletion of installation by button from VBS

Mon Sep 20, 2021 12:17 pm

Hi. I wrote a script on the Vbs, which displays a dialog with two buttons "Ok" and "Cancel". I want to make it so that when I click on the "Cancel" button, the installation is completed and the final dialog is shown in Advanced Installer. How can i do this?

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Сompletion of installation by button from VBS

Mon Sep 20, 2021 2:25 pm

Hello,

In order for me to have a better view about your scenario, could you please give me some more details (some screenshots with the custom action configuration and where you are executing it would also help)?

Normally, if no other logic is added to the messagebox, that should be the behavior. Basically, when the "Cancel" button is pressed, nothing should happen and the installation should continue (i.e. the next dialog should be spawned or whatever the event is on your dialog).

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

truejegor
Posts: 7
Joined: Thu Sep 16, 2021 9:49 am

Re: Сompletion of installation by button from VBS

Tue Sep 21, 2021 8:37 am

Hi, Catalin
My VBS code:

Code: Select all

Function MyVBScriptCA()
Dim sKey, bFound, Button
Set WshShell = WScript.CreateObject("WScript.Shell")

sKey = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ONLYOFFICE Desktop Editors_is1\UninstallString")

with CreateObject("WScript.Shell")
    
	Err.Clear
  ' turn off error trapping
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Button = MsgBox("The previous version of {#sAppName} detected, please click 'OK' button to uninstall it, or 'Cancel' to quit setup.",1,"Error")
	If Button = 1 Then
	MsgBox "Ok"
	WshShell.Run(sKey)
	End If
	If Button = 2 Then
	MsgBox "Cancel"
	
	'a = 1 / 0
	Exit Function
	On Error GoTo 0
	return Error
	End If     ' test for success
                   ' restore error trapping
end with
End Function

MyVBScriptCA()
Attachments
Screenshot_10.png
Screenshot_10.png (181.89KiB)Viewed 9181 times

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Сompletion of installation by button from VBS

Tue Sep 21, 2021 3:34 pm

Hello,

Thank you for your followup on this.

I believe the scenario is clear for me now. Basically, you want to abort the installation if the user presses cancel.

In order to achieve that, you could exit your VBScript with a code different than "0" if the user presses "Cancel".

Any other value returned by the custom action will be interpreted as a failure by the Windows Installer.

In addition to that, make sure to leave the "Fail installation if custom action returns an error" option checked.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”