Get INI file value with WiX

删除回忆录丶 提交于 2019-12-30 10:31:41

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1193091/get-ini-file-value-with-wix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!