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?
Answers (1)
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:
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.dpufIf 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.dpufIf 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 :)
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
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
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 guess rad33k is correct. We can add this to the Launch condition. - ajcbasilio 10 years ago