marceloavf
Posts: 10
Joined: Mon Jan 15, 2018 11:05 am

Abort installer if application is opened

Hi everyone!

I'm creating an installer and when it's running to install and user let some file open it goes to MsiRMFilesInUse Dialog, but at the end it's not closing the app, so I decided to create a custom action to allow us to have more control under it.

The problem is that I can't finish the installer in case that the user cancel to end the app proccess, I'll list below the proccess that I'm trying to do it.


First of all I detected if the proccess is running
Image

Then I ask the user to allow us to close it or cancel
Image

If OK button is pressed, I close the app
Image

If CANCEL button is pressed, I try to abort the installer, but nothing happens at this point and installation continues normally
Image

Thank you!
Catalin
Posts: 6598
Joined: Wed Jun 13, 2018 7:49 am

Re: Abort installer if application is opened

Hello,

In order to achieve what you want, you can use a "Display error message" instead of a VBScript custom action.

There are two ways of running a VBScript custom action. One of them is to run it as an inline script (as you did) and the second one is to use a "Launch attached file" custom action. The main problem here is that an inline VBScript custom action return code is always interpreted by Windows Installer as a success, thus you can not force your installation to fail using it. If you want to force your installation to fail based on a VBScript custom action, you should use a "Launch attached file" custom action instead.

Or you can also use a "Display error message" custom action, the installation will fail upon pressing the "Cancel" button from the "MessageBox", giving the user a message which will inform him that the installation can not continue if the does not stop / terminate the respective process.

In order to achieve those said above, you can go to "Custom Actions" page, add a "Display error message" custom action with the message that you want and the condition as it follows:

Code: Select all

BTN_PRESSED <> "IDOK"
This way, if the user presses the "Cancel" button from the "MessageBox", the installation will fail.

Let me know if this helps!

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
marceloavf
Posts: 10
Joined: Mon Jan 15, 2018 11:05 am

Re: Abort installer if application is opened

Catalin wrote:Hello,

In order to achieve what you want, you can use a "Display error message" instead of a VBScript custom action.

There are two ways of running a VBScript custom action. One of them is to run it as an inline script (as you did) and the second one is to use a "Launch attached file" custom action. The main problem here is that an inline VBScript custom action return code is always interpreted by Windows Installer as a success, thus you can not force your installation to fail using it. If you want to force your installation to fail based on a VBScript custom action, you should use a "Launch attached file" custom action instead.

Or you can also use a "Display error message" custom action, the installation will fail upon pressing the "Cancel" button from the "MessageBox", giving the user a message which will inform him that the installation can not continue if the does not stop / terminate the respective process.

In order to achieve those said above, you can go to "Custom Actions" page, add a "Display error message" custom action with the message that you want and the condition as it follows:

Code: Select all

BTN_PRESSED <> "IDOK"
This way, if the user presses the "Cancel" button from the "MessageBox", the installation will fail.

Let me know if this helps!

Regards,
Catalin
Excellent Catalin, I get it working using `Display error message` and the condition below:

Code: Select all

BTN_PRESSED AND BTN_PRESSED <> "IDOK"
Because sometimes the message box doesn't appear.

Thank you!
Catalin
Posts: 6598
Joined: Wed Jun 13, 2018 7:49 am

Re: Abort installer if application is opened

You're always welcome!

I am glad you got this working!

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

Return to “Building Installers”