/build/static/layout/Breadcrumb_cap_w.png

How to create custom action that will terminate MSI installation?

Hello All.

I'd like to ask on how  can I create a custom action that will terminate the MSI installation if the queried process is running?

Thanks!

[UPDATE]

I created VBS custom action stored in Custom Action

In-Script Execution: Immediate Execution

Install Exec Sequence: After AppSearch

Install Exec Condition: NOT INSTALLED


Here's the script.

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

checkProcess ("outlook.exe")

Function checkProcess(strProcessName)

Set colListOfProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name ='" & strProcessName & "'")

If colListOfProcess.count > 0 then

Session.Property("OUTLOOKFLAG") = 1

Else

Session.Property("OUTLOOKFLAG") = 0

End  If

End Function


I add a Launch Condition OUTLOOKFLAG <> 1

But the installer was successfully launched even if outlook is running. Did I missed something?


2 Comments   [ + ] Show comments
  • Hi ajcbasilio,

    it depends what you really need to do. If you want to stop installation if some condition is not met you may consider using of LaunchCondition table.
    If it is needed to terminate instalaltion in CustomAction, you may use one of the available return codes:
    http://msdn.microsoft.com/en-us/library/aa368072%28v=vs.85%29.aspx
    http://msdn.microsoft.com/en-us/library/aa371254%28v=vs.85%29.aspx
    so you can create VBScript CustionAction stored in binary table, and call function that will return 3 if process is running, eg:

    Function MyVBScriptCA()
    'some piece of code to determine if your process is running
    If Process=1 Then
    'return 3 - break the MSI installation
    MyVBScriptCA = 3
    Exit Function
    Else
    'return 1 - success
    MyVBScriptCA = 1
    Exit Function
    End If

    End Function - rad33k 10 years ago
    • Hello rad33k.

      I created VBS custom action stored in Custom Action

      In-Script Execution: Immediate Execution
      Install Exec Sequence: After AppSearch
      Install Exec Condition: NOT INSTALLED

      Here's the script.


      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

      checkProcess ("outlook.exe")

      Function checkProcess(strProcessName)
      Set colListOfProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name ='" & strProcessName & "'")

      If colListOfProcess.count > 0 then
      Session.Property("OUTLOOKFLAG") = 1
      'wscript.echo "Outlook is running"
      Else
      Session.Property("OUTLOOKFLAG") = 0
      'wscript.echo "Outlook is not running"
      End If
      End Function

      I add a Lauch Condition OUTLOOKFLAG <> 1

      But the installer was successfully launched even if outlook is running. Did I missed something? - ajcbasilio 10 years ago
  • I think a good question is why you want a CA to stop an MSI - what condition could you run into that would warrant such an action? All installation parameters are tested before the MSI starts the installation so there shouldn't be a need to stop it. You may be over-thinking this. - vjaneczko 10 years ago
    • My bad. My purpose is before MSI will run it will check if the process is running if yes it will not proceed.

      I guess rad33k is correct. We can add this to the Launch condition. - ajcbasilio 10 years ago

Answers (1)

Posted by: rad33k 10 years ago
Fourth Degree Brown Belt
0
Are you sure that you Script is working?
When I've tried to launch your script via MSI CustomAction it throws error in line 15 - type mismatch "Session.Property".
I've enclosed values in quotation marks and then it worked:
When I've enclosed values in a quotation marks it started working: - See more at: http://www.itninja.com/question/how-to-create-custom-action-that-will-terminate-msi-installation#sthash.f5nJINjM.dpuf

If colListOfProcess.count > 0 then

Session.Property("OUTLOOKFLAG") = 1

Else

Session.Property("OUTLOOKFLAG") = 0

End  If

- See more at: http://www.itninja.com/question/how-to-create-custom-action-that-will-terminate-msi-installation#sthash.f5nJINjM.dpuf

If colListOfProcess.count > 0 then

Session.Property("OUTLOOKFLAG") = 1

Else

Session.Property("OUTLOOKFLAG") = 0

End  If

- See more at: http://www.itninja.com/question/how-to-create-custom-action-that-will-terminate-msi-installation#sthash.f5nJINjM.dpuf
If colListOfProcess.count > 0 then
    Session.Property("OUTLOOKFLAG") = "1"
Else
    Session.Property("OUTLOOKFLAG") = "0"
End If

Besides that if your MSI has to support non silent installation you should place this Action in both sequences (InstallUISequence and InstallExecuteSequence) before LaunchConditions action.

Just to make sure - condition should be OUTLOOKFLAG=0 becuase according to http://msdn.microsoft.com/en-us/library/aa369752%28v=vs.85%29.aspx:

Condition
    Expression that must evaluate to True for installation to begin.

so in you case OUTLOOKFLAG will be equall 1 if Outlook.exe is running and 0 if not so 0 (OUTLOOKFLAG) must equal to 0 (Conditional statement =0) to start installation ;)

If you would still have any question please let me know, I can send you sample MSI.

EDIT:
I didn't notice that your condition is "OUTLOOKFLAG <> 1" (condition is empty in above post) - it should be OK too :)

OUTLOOKFLAG <> 1

If colListOfProcess.count > 0 then

Session.Property("OUTLOOKFLAG") = 1

Else

Session.Property("OUTLOOKFLAG") = 0

End  If

- See more at: http://www.itninja.com/question/how-to-create-custom-action-that-will-terminate-msi-installation#sthash.f5nJINjM.dpuf
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ