0

I have a two part question about editing an MSI with VBScript.

  1. The below code will work with a static value (C:\users\x etc) to place into the MSI 'Property' table. However, if I use a predefined variable then it inserts the variable name as text into the MSI and not what that variable translated to. How do I get the msi.OpenView function to accept a variable for the value?

    The variable is created from a commandline argument.

    strNewServerName = WScript.Arguments.Item(0)
    
    Set record = msiInstaller.CreateRecord(1)
    Set view = msi.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES ('SERVERNAME', 'strNewServerName')")
    
    view.Execute record
    
  2. The view.Execute will error unless the property/row in the MSI is empty. I have to take out all the fields I'm updating in the source MSI before I commit the new one for this to function. Is there a way of triggering the msi.OpenView("INSERT INTO...") with an overwrite command for whatever is already in the row/table?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
n00borama
  • 88
  • 1
  • 4

1 Answers1

1

There are to ways to interpolate a variable's content into a string: concatenation and replacement. As in:

>> v = "content"
>> WScript.Echo "pipapo '" & v & "' popapi"
>> WScript.Echo Replace("pipapo '@' popapi", "@", v)
>>
pipapo 'content' popapi
pipapo 'content' popapi
>>

To change an existing record, use "Update" as demonstrated here.

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Thanks, ok the Update function makes sense. Not quite sure how you mean the replacement of text will work. Whatever is written into the second set of quotes in - VALUES ('SERVERNAME', 'strNewServerName')") - gets written as clear text with all logic stripped. – n00borama Jun 15 '16 at 10:09
  • Ended up finding a way to do this similar to what you'd described but I couldn't quite make sense of yours. set view = msi.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES ('SERVERPORT', '" & strNewServerPort & "')") – n00borama Jun 15 '16 at 15:22