Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get INI file value with WiX

Tags:

wix

ini

wix3

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".

like image 400
Ian Grainger Avatar asked Mar 01 '23 12:03

Ian Grainger


2 Answers

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.

like image 102
saschabeaumont Avatar answered Mar 07 '23 02:03

saschabeaumont


I know this is an old thread, but I was hoping to save someone from the same pain I went through....

This does read a value from an ini file, at least so far as my tests with Wix3.5 and 3.6 beta. i.e.

<Property Id="MY_PROPERTY">
        <IniFileSearch Id="myIniSearch" Name="myConfigFile.ini" Section="section1" Key="name" Type="raw" />
    </Property>

    <Condition Message="myconfigfile not def.">MY_PROPERTY</Condition>

With the corresponding ini file saved in C:\windows\myConfigFile.ini (Windows 7) :

[section1]
name=testing

However, I burned many hours trying to figure out why this appeared to not work before realising that the ini file must be ANSI and not UTF8! An ANSI encoded .ini file in the correct location i.e. c:\Windows\some.ini will work.

UTF8 files are just not read, no error occurs, the property assignment just doesn't happen.

like image 30
Paul George Avatar answered Mar 07 '23 01:03

Paul George