tags:

views:

747

answers:

2

I'd like to read a value from an INI file in a WiX installer. I've just tried to use IniFileSearch, but this looks for an INI file or a path specified in an INI file (the documentation isn't clear), it doesn't read a value from an INI file.

Do I need a customaction to do this? And if so, what would people suggest? Seems very strange if WiX doesn't have this, though!

Code I'm using:

<Property Id="SP">
    <IniFileSearch Id="SearchSPVersion" Name="sp.ini" Section="ServicePack"
    Key="Version" Type="raw">
     <DirectorySearch Id="SPIniFilePath" Path="[CFGPATH]">
      <FileSearch Id="SPIniFile" Name="sp.ini"/>
     </DirectorySearch>
    </IniFileSearch>
</Property>

INI file:

[ServicePack] 
Version=1

I've tried with and without the directory and file search (using full path in 'name'), and I've tried type = "raw", "file" and "directory".

A: 

The Windows Installer documentation states that the .ini file must be present in the default Microsoft Windows directory.

It's a bit confusing as FileSearch and DirectorySearch are valid WiX children, however I believe this is for searching for a file or directory specified within the INI file itself. You'll notice the three types of values you can search for within an INI file are directory, file and raw.

It's a limitation of Windows Installer, not of WiX. The Microsoft interfaces for reading INI files (e.g. GetPrivateProfileString) looks in the Windows folder if a path is not specified. I guess the Windows Installer team decided not to simplify things and only support INI files in the Windows folder by not allowing a dynamic path.

sascha
Right. That's sucky, isn't it?
Ian Grainger
Well, only if you're still using INI files. Shouldn't you be using the registry these days?
sascha
a) It's only in an INI file, if it was in the registry I'd be fine.b) On a tangent: I'm not sure whether Microsoft is planning to ditch the registry ever, but as a concept I personally don't like it... But that's not really important.
Ian Grainger
A: 

Try this in a DTF custom action: INI File Reader in C#

KMoraz
:( customactions.
Ian Grainger