How to parse strings in MSI

How to manipulate the contents of Properties

How to pass Property values to VBS Scripts or WiseScripts


MSI Script has nothing to manipulate character strings (ie LEFT( ), RIGHT( ), MID( ), etc). To do this we must use a VBS script or WiseScript. To do either, we must call the scripts from MSI Script.


The hard thing is determining where in MSI script to do this. This all depends on the Property you are trying to use. If you try to use a property that is set after the Custom Action you added, you won't get what you're expecting.

Frame45


Parsing with VBS script

(With help from Wise KB Article #1548)

For an example, let's try to extract the name of MSI file from the OriginalDatabase property. The OriginalDatabase property give us the name of the MSI file but it includes the full path, we want to parse for the MSI file name only.


-Go to the MSI Script view:

-Select the Execute Immediate page

-Place it after the CostFinalize action (This is usually safe since most properties are now defined)

-In the left column select Call VBScript from Embedded code

-Custom Action Name: MrParseIT (This is just a cutesy label, it's whatever you want)

-Enter the VBScript to execute:



'based on the InstrRev entry in Script56.CHM

Dim MyString, SearchChar, MyPos, Resultstr


'Read from windows installer property.

SearchString = Session.Property("OriginalDatabase")

SearchChar = "\" ' Search for "\".


'edit SearchString

MyPos = InstrRev(SearchString, SearchChar, -1, 1) 'textual comparison starting at the end.


'InstrRev counts from the end of the string so we have to switch that around for Right()

MyPos = Len(SearchString)-MyPos


Resultstr = Right(SearchString,MyPos)


'For testing only

'MsgBox"Resultstr has:"&Resultstr&Vbcrlf&"SearchString has:"&SearchString&" ", 0, "test"


'Write value to windows installer property.

Session.Property("MYNAMEIS") = Resultstr


The name of the property that is set at the end is: MYNAMEIS

Should look like this:


Frame47


Frame49


Parsing with WiseScript

(With help from Wise KB Article #1956)

For an example, let's try to extract the name of MSI file from the OriginalDatabase property. The OriginalDatabase property give us the name of the MSI file but it includes the full path, we want to parse for the MSI file name only.


-Go to the MSI Script view:

-Select the Execute Immediate page

-Place it after the CostFinalize action (This is usually safe since most properties are now defined)

-In the left column select Call WiseScript from Installation

-Custom Action Name: MrParseIT (This is just a cutesy label, it's whatever you want.)

-For the WiseScript EXE file: MrParseIT (Again, whatever you want, I'm just consistent..)

-Click the Options button and select Create New WiseScript


-A Save As window appears. Browse to where you want your WiseScript to be save and click the Save button. I would suggest the same directory as where your WSI is located. That way all the files needed to build the package stays together.


-WiseScript Editor (or WiseScript Express) opens

-Paste in this WiseScript:


item: Remark

Text=Read from windows installer property.

end

item: Custom Script Item

Filename=Get Windows Installer Property.wse

Variable Name1=_PROPERTYNAME_

Variable Value1=OriginalDatabase

Variable Name2=_PROP_VAR_

Variable Value2=SearchString

Variable Name3=HELPFILE

Variable Value3=\\parisdmres02\WPSDIR$\HELP\WiseScriptEditor.chm

end

item: Remark

Text= Search for "\".

end

item: Set Variable

Variable=SEARCHCHAR

Value=\

end

item: Remark

end

item: Remark

Text=edit SearchString

end

item: Parse String

Source=%SearchString%

Pattern=%SEARCHCHAR%

Variable1=JUNK

Variable2=RESULTSTR

Flags=00000100

end

item: Remark

end

item: Remark

Text=For testing only

end

remarked item: Display Message

Title=test

Text=Resultstr has: %Resultstr%

Text=SearchString has: %SearchString%

end

item: Remark

end

item: Remark

Text=Write value to windows installer property.

end

item: Custom Script Item

Filename=Set Windows Installer Property.wse

Variable Name1=_PROPERTYNAME_

Variable Value1=MYNAMEIS

Variable Name2=HELPFILE

Variable Value2=\\parisdmres02\WPSDIR$\HELP\WiseScriptEditor.chm

Variable Name3=_PROPERTYVAL_

Variable Value3=Resultstr

end



Yea, it's gobbledygook alright.

But if you paste in onto the WiseScript Editor it looks like this (Trust me!):


-Click Compile and exit out of WiseScript Editor.

-This will bring you back to your package and you'll have something like this:

-Click Ok

-Click Compile to compile your MSI that will now contain the WiseScript.


Frame51