Get INI file value with WiX
Asked Answered
H

3

6

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

Hovel answered 28/7, 2009 at 9:54 Comment(3)
Is this value used anywhere other than the install?Cumulonimbus
Yes. In a condition. Otherwise I wouldn't need to get it.Hovel
I have similar need. I need only 2 or 3 values, I may use env variables for that. I do not want to place temp files in c:\ or c:\windows .Plectognath
O
0

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

Ouch answered 29/7, 2009 at 15:24 Comment(1)
Mentioned path is not available. What is the solution for this question? Can you please give the solution to this : #70243657Rebato
E
5

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.

Ebsen answered 29/7, 2009 at 2:19 Comment(6)
Right. That's sucky, isn't it?Hovel
Well, only if you're still using INI files. Shouldn't you be using the registry these days?Ebsen
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.Hovel
"It's a limitation of Windows Installer, not of WIX." In researching this question I've seen this statement multiple times. It would be more correct to state that it is a limitation of the Windows installer and of WIX. It isn't like WIX is forced to not extend where the Windows Installer falls down.Smoky
@MichaelHunter that has to be the best comment I've read! It shares my sentiments toward that statement.Kreager
@Ebsen And how well does the Windows registry work for network installations?Roice
I
5

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.

Irrational answered 23/12, 2011 at 11:49 Comment(1)
Looking at your example it seems that you agree with @Ebsen that the INI file must be stored in the Windows directory. So bascially Windows forces developers to clutter the Windows directory with their INI files? Oh well....Roice
O
0

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

Ouch answered 29/7, 2009 at 15:24 Comment(1)
Mentioned path is not available. What is the solution for this question? Can you please give the solution to this : #70243657Rebato

© 2022 - 2024 — McMap. All rights reserved.