سؤال

I have a scenario in which I need to update a ini file during installation. I am using the IniFileElement thusly:

<Component Id="TestIni"
              Guid="{058D0B2B-0145-4743-969F-C5AACA992936}" Directory="INSTALLFOLDER">
  <CreateFolder />
<IniFile Id="Ini2"    Action="addLine"    
 Directory="INSTALLFOLDER" Name="File.conf"         
 Key="theKey"    
 Value="[ComputerName]" />
</Component>

But it does not work since the Section attribute is missing. Is there a way I can write to the "default" section of the IniFile? My Ini file does not have sections defined.

هل كانت مفيدة؟

المحلول

Here's what I can tell you... the WiX XSD for the section attribute to exist and have a value. The underlying Windows Installer IniFile table also says that the Section column cannot be null. It also says it's of type Formatted which means I can give it a property name for a value. Just to really push the limites I tried to give it a null property ( [FAKE] ) and see what would happen. It failed with an error 2109 which is Section missing for .ini action.

So I'll admit, I'm getting a little old and forgetful.... In all my years, I don't recall INI values without sections. According to Wikipedia "Keys may (but need not) be grouped into arbitrarily named sections." I don't believe this though. There are no references for this assertion and the references that are listed are for ".conf" files (which are not .INI files) and a bunch of suspect web sites.

Let's dig a little deeper. GetPrivateProfileString function says "The name of the section containing the key name. If this parameter is NULL, the GetPrivateProfileString function copies all section names in the file to the supplied buffer."

WritePrivateProfileString function says for lpAppName "The name of the section to which the string will be copied. If the section does not exist, it is created. The name of the section is case-independent; the string can be any combination of uppercase and lowercase letters." It does not say that it can be null.

So, in my opinion INI files cannot / should not have keys without sections. Your ".conf" file may look like an INI file but it is not an INI file and you'll need custom actions to do search and replaces. Either that or you redesign your application (if possible) to conform to INI specifications.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top