<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Installation Developer &#187; How to Work with Configuration Files, Part 2</title>
	<atom:link href="http://www.installationdeveloper.com/341/how-to-work-with-configuration-files-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.installationdeveloper.com</link>
	<description>InstallShield Training - InstallShield Tutorials</description>
	<lastBuildDate>Sat, 04 Sep 2010 14:49:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to Work with Configuration Files, Part 2</title>
		<link>http://www.installationdeveloper.com/341/how-to-work-with-configuration-files-part-2/</link>
		<comments>http://www.installationdeveloper.com/341/how-to-work-with-configuration-files-part-2/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 22:24:20 +0000</pubDate>
		<dc:creator>Rod_Maupin</dc:creator>
				<category><![CDATA[InstallShield Training]]></category>
		<category><![CDATA[installshield class]]></category>
		<category><![CDATA[installshield classes]]></category>
		<category><![CDATA[installshield course]]></category>
		<category><![CDATA[installshield courses]]></category>
		<category><![CDATA[installshield programmer]]></category>
		<category><![CDATA[Installshield Tutorial]]></category>
		<category><![CDATA[installshield tutorials]]></category>

		<guid isPermaLink="false">http://www.installationdeveloper.com/?p=341</guid>
		<description><![CDATA[In Part 1 of this series, we looked at how to create a configuration file in both&#160;Basic MSI and InstallScript projects.&#160; In Part 2, we will show to read values from a configuration file in&#160;both project types. In a Basic MSI project, there is no built-in functionality in the Windows Installer that will automatically read [...]]]></description>
			<content:encoded><![CDATA[<p>
In Part 1 of this series, we looked at how to create a configuration file in both&nbsp;<strong>Basic MSI</strong> and <strong>InstallScript</strong> projects.&nbsp; In <strong>Part 2</strong>, we will show to read values from a configuration file in&nbsp;both project types.
</p>
<p>
In a <strong>Basic MSI</strong> project, there is no built-in functionality in the <strong>Windows Installer</strong> that will automatically read values from a configuration file.&nbsp; So, we will have to write a <strong>Custom Action (CA)</strong>, and more specifically, we will want to write an <strong>InstallScript CA</strong>.
</p>
<p>
Let&#39;s remind ourselves about&nbsp;the configuration file we created in <strong>Part 1</strong>.&nbsp; Here are the contents of the <strong>Mega View.ini</strong> file:
</p>
<blockquote>
<p>
	<strong>[general]<br />
	title=Mega View &#8211; The Ultimate Viewer</strong>
	</p>
</blockquote>
<p>
Next,&nbsp;we will go to the <strong>Behavior and Logic</strong> section, <strong>InstallScript</strong> view, and create an <strong>InstallScript</strong> file.&nbsp; In the middle pane, right-click <strong>Files</strong> and select <strong>New Script File</strong>.&nbsp; You can name the file <strong>setup.rul</strong>.&nbsp; Then, we need to create an <strong>InstallScript </strong>function by adding a prototype and adding the function skeleton.&nbsp; Here is the prototype:
</p>
<blockquote>
<p>
	<strong>export prototype ReadConfigFile();</strong>&nbsp;
	</p>
</blockquote>
<p>
We&#39;ll call the function <strong>ReadConfigFile()</strong> and it will have no parameters.&nbsp; Here is the code for the function:
</p>
<blockquote>
<p>
	<strong>///////////////////////////////////////////////////////////////////////////////<br />
	//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
	// Function:&nbsp; ReadConfigFile()<br />
	//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
	///////////////////////////////////////////////////////////////////////////////</strong>
	</p>
<p>
	<strong>Function ReadConfigFile(hMSI)</strong>
	</p>
<p>
	<strong>&nbsp;&nbsp;&nbsp; STRING szPath;<br />
	&nbsp;&nbsp;&nbsp; STRING szInstallFolder;<br />
	&nbsp;&nbsp;&nbsp; STRING szSectionName;<br />
	&nbsp;&nbsp;&nbsp; STRING szKeyName;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;<br />
	&nbsp;&nbsp;&nbsp; NUMBER nResult<br />
	&nbsp;&nbsp;&nbsp; <br />
	begin<br />
	&nbsp; // build path to config file</strong>
	</p>
<p>
	<strong>&nbsp; szPath = szInstallFolder ^ &quot;Mega View.ini&quot;;</strong>
	</p>
<p>
	<strong>&nbsp; // read&nbsp;string value from config file&nbsp;</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; szSectionName = &quot;general&quot;;<br />
	&nbsp; szKeyName = &quot;title&quot;;<br />
	&nbsp; GetProfString(szPath, szSectionName, szKeyName, szResult);</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; // do something with this value</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; Do something with szResult;</strong>
	</p>
</blockquote>
<blockquote>
<p class="ps_Syntax">
	<strong>&nbsp;&nbsp;return ERROR_SUCCESS;<br />
	end;<br />
	</strong><strong>&nbsp;</strong>
	</p>
</blockquote>
<p class="ps_Syntax">
The function is pretty simple.&nbsp; We just build a path to the config file.&nbsp; Then we call <strong>GetProfString()</strong> to get the value from the file.&nbsp; We set the <strong>Section</strong> to &quot;<strong>general</strong>&quot; and the <strong>Key</strong> to &quot;<strong>title</strong>&quot;, since that was where the value was in the config file we created in <strong>Part 1</strong>.
</p>
<p class="ps_Syntax">
Now, we need to call the function by creating a <strong>Custom Act</strong>ion.&nbsp; Just to to the <strong>Custom Actions and Sequences</strong> view under the <strong>Behavior and Logic</strong> section, in the middle pane right-click <strong>Custom Actions</strong> and select <strong>Custom Action Wizard</strong>.&nbsp; We will define a <strong>CA</strong> with these characteristics:
</p>
<blockquote>
<p class="ps_Syntax">
	Function Name: <strong>GetConfigFileData</strong><br />
	Return Processing: <strong>Synchronous (Ignores exit code)</strong><br />
	In-Script Execution: <strong>Immediate Execution</strong><br />
	Execution Scheduling: <strong>Always execute</strong><br />
	Install UI Sequence: <strong>After CostFinalize</strong>
	</p>
</blockquote>
<p class="ps_Syntax">
We will just call the <strong>CA</strong> at the beginning of the <strong>UI Sequence</strong> after <strong>CostFinalize</strong> since we want to read the value from the config file before we actually do anything in the installation program.
</p>
<p class="ps_Syntax">
That takes care of the <strong>Basic MSI</strong> example.&nbsp; The <strong>InstallScript</strong> example is actually a lot easier.&nbsp; We can just call the <strong>GetProfString()</strong> function directly from the script.
</p>
<p class="ps_Syntax">
In the <strong>InstallScript</strong> view, we will add our code near the beginning of the <strong>OnFirstUIBefore</strong> event handler, and we&#39;ll do it&nbsp;between <strong>Dlg_Start</strong> and <strong>Dlg_SdWelcome</strong>.&nbsp; Here is the code:
</p>
<blockquote>
<p class="ps_Syntax">
	<strong>Dlg_Start:<br />
	&nbsp; // build path to config file</strong>
	</p>
<p>
	<strong>&nbsp; szPath = TARGETDIR ^ &quot;Mega View.ini&quot;;</strong>
	</p>
<p>
	<strong>&nbsp; // read&nbsp;string value from config file&nbsp;</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; szSectionName = &quot;general&quot;;<br />
	&nbsp; szKeyName = &quot;title&quot;;<br />
	&nbsp; GetProfString(szPath, szSectionName, szKeyName, szResult);</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; // do something with this value</strong>
	</p>
<p class="ps_Syntax">
	<strong>&nbsp; Do something with szResult;</strong>
	</p>
<p class="ps_Syntax">
	<strong>Dlg_SdWelcome:<br />
	</strong>
	</p>
</blockquote>
<p class="ps_Syntax">
You see it is basically the same code as in the <strong>Basic MSI</strong> example.&nbsp; The <strong>Section Name</strong> is &quot;<strong>general</strong>&quot; and the <strong>Key Name</strong> is &quot;<strong>title</strong>&quot; and the value is stored in the <strong>szResult</strong> variable.&nbsp; Now realize that you will have&nbsp;to declare the variables earlier in the script.&nbsp; But, you probably knew that already.
</p>
<p class="ps_Syntax">
That wraps up our example of creating a configuration file in both <strong>Basic MSI</strong> and <strong>InstallScript </strong>projects.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202&amp;bodytext=%0D%0AIn%20Part%201%20of%20this%20series%2C%20we%20looked%20at%20how%20to%20create%20a%20configuration%20file%20in%20both%26nbsp%3BBasic%20MSI%20and%20InstallScript%20projects.%26nbsp%3B%20In%20Part%202%2C%20we%20will%20show%20to%20read%20values%20from%20a%20configuration%20file%20in%26nbsp%3Bboth%20project%20types.%20%0D%0A%0D%0A%0D%0AIn%20a%20Basic%20MSI%20pro" title="Digg"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202&amp;notes=%0D%0AIn%20Part%201%20of%20this%20series%2C%20we%20looked%20at%20how%20to%20create%20a%20configuration%20file%20in%20both%26nbsp%3BBasic%20MSI%20and%20InstallScript%20projects.%26nbsp%3B%20In%20Part%202%2C%20we%20will%20show%20to%20read%20values%20from%20a%20configuration%20file%20in%26nbsp%3Bboth%20project%20types.%20%0D%0A%0D%0A%0D%0AIn%20a%20Basic%20MSI%20pro" title="del.icio.us"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;t=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="Facebook"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.newsvine.com/_tools/seed&amp;save?u=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;h=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="NewsVine"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/newsvine.png" title="NewsVine" alt="NewsVine" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="Reddit"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="StumbleUpon"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202&amp;annotation=%0D%0AIn%20Part%201%20of%20this%20series%2C%20we%20looked%20at%20how%20to%20create%20a%20configuration%20file%20in%20both%26nbsp%3BBasic%20MSI%20and%20InstallScript%20projects.%26nbsp%3B%20In%20Part%202%2C%20we%20will%20show%20to%20read%20values%20from%20a%20configuration%20file%20in%26nbsp%3Bboth%20project%20types.%20%0D%0A%0D%0A%0D%0AIn%20a%20Basic%20MSI%20pro" title="Google Bookmarks"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;submitHeadline=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202&amp;submitSummary=%0D%0AIn%20Part%201%20of%20this%20series%2C%20we%20looked%20at%20how%20to%20create%20a%20configuration%20file%20in%20both%26nbsp%3BBasic%20MSI%20and%20InstallScript%20projects.%26nbsp%3B%20In%20Part%202%2C%20we%20will%20show%20to%20read%20values%20from%20a%20configuration%20file%20in%26nbsp%3Bboth%20project%20types.%20%0D%0A%0D%0A%0D%0AIn%20a%20Basic%20MSI%20pro&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202%20-%20http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F" title="Twitter"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F" title="Technorati"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="Live"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;title=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202&amp;source=Installation+Developer+InstallShield+Training+-+InstallShield+Tutorials&amp;summary=%0D%0AIn%20Part%201%20of%20this%20series%2C%20we%20looked%20at%20how%20to%20create%20a%20configuration%20file%20in%20both%26nbsp%3BBasic%20MSI%20and%20InstallScript%20projects.%26nbsp%3B%20In%20Part%202%2C%20we%20will%20show%20to%20read%20values%20from%20a%20configuration%20file%20in%26nbsp%3Bboth%20project%20types.%20%0D%0A%0D%0A%0D%0AIn%20a%20Basic%20MSI%20pro" title="LinkedIn"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.installationdeveloper.com%2F341%2Fhow-to-work-with-configuration-files-part-2%2F&amp;t=How%20to%20Work%20with%20Configuration%20Files%2C%20Part%202" title="MySpace"><img src="http://www.installationdeveloper.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.installationdeveloper.com/341/how-to-work-with-configuration-files-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
