RegistryValue Element of type multiString

2019-08-09 22:29发布

The WiX doc says that if type is MultiString then we can specify actions, append, prepend, write(default). what is mean by write action here? does it simply overwrites earlier entry, or adds with semicolon? if it just overwrites earlier entry, how it is different from type "string"

1条回答
我命由我不由天
2楼-- · 2019-08-09 23:19

I believe write overwrites the existing value(s) whether string or multi string, and enforces whatever new string type is specified. Multi string is different from string because you can add a list of stings via the <MultiStringValue> element (a regular string value can not do this - it cannot have MultiStringValue child elements):

<RegistryValue Id="R3" Root="HKCU" Action="write" Key="Software\_WiXTest"
               Name="multi" Type="multiString" Value="samplemultistring">
    <MultiStringValue>test2.1</MultiStringValue>
    <MultiStringValue>test2.2</MultiStringValue>
</RegistryValue>

For multi string prepend adds the string at the start of the string list and append adds the string to the end of the string list. Multi strings are not semicolon delimited as far as I know, but a sequence of null-terminated strings, terminated by an empty string (\0). See Registry Value Types:

Sample Multi String: String1\0String2\0String3\0LastString\0\0, and how it looks in regedit.exe (with a contrasting regular string):

View of a multi string in regedit.exe


Just dumping some sample test markup - warts and all :-) - you can use for testing if you'd like:

<Component Feature="MainApplication" Id="HKCU" Guid="*">
  <RegistryValue Id="R1" Root="HKCU" Key="Software\_WiXTest" KeyPath="yes" 
                 Name="WiXWritten" Type="string" Value="R1 regular string">
  </RegistryValue>
  <RegistryValue Id="R2" Root="HKCU" Action="append" Key="Software\_WiXTest" 
                 Name="WiXWritten" Type="multiString" Value="R2 sample multistring">
      <MultiStringValue>test1.1</MultiStringValue>
      <MultiStringValue>test1.2</MultiStringValue>
      <MultiStringValue>test1.3</MultiStringValue>
  </RegistryValue>
  <RegistryValue Id="R3" Root="HKCU" Action="write" Key="Software\_WiXTest"
                 Name="WiXWritten" Type="multiString" Value="R3 sample multistring">
     <MultiStringValue>test2.1</MultiStringValue>
     <MultiStringValue>test2.2</MultiStringValue>
   </RegistryValue>
 </Component>

Some of the elements above will overwrite each other on install - as far as I understand that's what wasn't clear to you. Maybe dump this in your WiX source and give it a test spin.

By repeating several RegistryValue elements you can get the same effect as the MultiStringValue elements.

Try changing the last RegistryValue element's Action="write" to Action="append". Now it adds to the existing multi string instead of overwriting it. It should become: R2 sample multistring\0test1.1\0test1.2\0test1.3\0R3 sample multistring\0test2.1\0test2.2\0\0.

查看更多
登录 后发表回答