Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

How to change REMOVE property in VBscript

I am trying to run a custom action written in VBscript to change the REMOVE property. This can't be done through the normal means (in the Upgrade table) because of a legacy of badly written installers.

Question 1: Where should I place the custom action? I think it should be between RemoveExistingProducts and InstallInitialize in the InstallExecute sequence.

Question 2: What properties should it have? I've currently got synchronous, immediate execution, always execute.

Question 3: My script currently starts with:
myInstaller = Session.Installer
as I need to use a test similar to:
if (myInstaller.FeatureState(productCode, featureName) = 3) then ...
later on, but every time I run it (with logging turned on), I get an error that says:
"Info 1720.There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action <MyScriptName> script error -2146827850, Microsoft VBScript runtime error: Object doesn't support this property or method: 'myInstaller' Line 1, Column 1,"
I've searched the online help, Microsoft SDK online help, done a Google search and browsed several forums and can't find any explanations. I'm desperate. Can anyone explain what's wrong?
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: How to change REMOVE property in VBscript

Hello,
Question 1: Where should I place the custom action? I think it should be between RemoveExistingProducts and InstallInitialize in the InstallExecute sequence.
It's ok.
Question 2: What properties should it have? I've currently got synchronous, immediate execution, always execute.
This seems ok too.

Regarding Question 3, you want to do Session.FeatureState, not Session.Installer.FeatureState as your script is doing now. Try using "myInstaller = Session"

For directly changing properties, you can use for example:

Code: Select all

Session.Property("YOURPROPERTYNAME_HERE") = <somevalue>
Let me know how this worked.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

Re: How to change REMOVE property in VBscript

I can't use Session.FeatureState(feature), because I'm getting the feature state of a feature from a different product, hence it has to be Session.Installer.FeatureState(product, feature) so that I can specify the other product.
Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

Re: How to change REMOVE property in VBscript

If I remove the references to the myInstaller variable and change "myInstaller.FeatureState(productCode, feature)" to "Session.Installer.FeatureState(productCode, feature)", I get the following error:
"Info 1720.There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action <myScript> script error -2146828275, Microsoft VBScript runtime error: Type mismatch: 'Session.Installer.FeatureState' Line 59, Column 1,"

Does this give any further clues as to what is wrong? The productCode and feature variables both contain strings. It looks to me like the Installer object does not exist when the script is run, but I can't understand why this would be so.
Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

Re: How to change REMOVE property in VBscript

Any idea why this VBScript error occurs? I've tried avoiding getting the feature state and doing a search by file name instead, but this presented a whole slew of other insurmountable problems, so I'd prefer to revert to getting the feature state.

I should point out that I'm trying to overcome legacy problems when upgrading from old versions of our products that were built using InstallShield - things like using the same ProductCode for two different versions, using invalid characters in the version, using a trailing space after the version, not placing the InstallLocation in the registry, changing the feature names between versions, not preventing a product from downgrading, having an "invisible" core feature with an uninstall shortcut and so on.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

How to check for the feature state of some installed product

Hello,

You will need to instantiate an installer object using CreateObject.
Simply change the two variables productCode and feature accordingly in the below script, and save it to a vbs:

Code: Select all

Const msiInstallStateNotUsed      = -7
Const msiInstallStateBadConfig    = -6
Const msiInstallStateIncomplete   = -5
Const msiInstallStateSourceAbsent = -4
Const msiInstallStateInvalidArg   = -2
Const msiInstallStateUnknown      = -1
Const msiInstallStateBroken       =  0
Const msiInstallStateAdvertised   =  1
Const msiInstallStateRemoved      =  1
Const msiInstallStateAbsent       =  2
Const msiInstallStateLocal        =  3
Const msiInstallStateSource       =  4
Const msiInstallStateDefault      =  5

Dim feature, features, parent, state, featureInfo

set installer = Wscript.CreateObject("WindowsInstaller.Installer")

Change the productCode and feature variables accordingly
Const productCode = "{07042B57-006F-4C37-BACE-0B19763DF7B1}"
feature = "MainFeature"

state = installer.FeatureState(productCode, feature)

Select Case(state)
    Case msiInstallStateBadConfig:    state = "Corrupt"
    Case msiInstallStateIncomplete:   state = "InProgress"
    Case msiInstallStateSourceAbsent: state = "SourceAbsent"
    Case msiInstallStateBroken:       state = "Broken"
    Case msiInstallStateAdvertised:   state = "Advertised"
    Case msiInstallStateAbsent:       state = "Uninstalled"
    Case msiInstallStateLocal:        state = "Local"
    Case msiInstallStateSource:       state = "Source"
    Case msiInstallStateDefault:      state = "Default"
    Case Else:                        state = "Unknown"
End Select

MsgBox state
Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

Re: How to change REMOVE property in VBscript

I have tried this before and it didn't work. I tried it again and got the following error in the log:
Info 1720.There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor. Custom action UpgradeSelection script error -2146827864, Microsoft VBScript runtime error: Object required: 'Wscript' Line 15, Column 1,

This is the line that says:
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Warrigal
Posts: 43
Joined: Thu Jun 26, 2008 8:20 am

Re: How to change REMOVE property in VBscript

I've been searching other forums and the line that says Set installer = Wscript.CreateObject("WindowsInstaller.Installer") is a no-no.

I have eventually worked it out. You have to do this:

Code: Select all

Dim installer
Set installer = Nothing
Set installer = Session.Installer
I do not understand the vagaries of VBScript, but this seems to work for me. Presumably, setting installer to 'Nothing' tells VBScript that it is an object rather than a primitive data type.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: How to change REMOVE property in VBscript

Hello,

Sorry about that. Indeed, the Wscript object is not available during an install, that bit slipped past me.
The solution you posted is the correct one, thanks for pointing it out.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”