Page 1 of 1

Writing values from a text file to the registry

Posted: Mon Sep 25, 2006 9:00 am
by tomriley
I have added a text file to the project as a support file, and intend to use it to configure the set of registry values that will be written on install (by storing values in this file as a comma separated list Type, Key, Name, Value.

I am currently using the following script to do this:

Set Variable REGISTRY_ENTRY to
Set Variable REGISTRY_ENTRY_EOF to
Set Variable REGISTRY_TYPE to
Set Variable REGISTRY_VALUE to
Set Variable REGISTRY_KEY to
Set Variable REGISTRY_DATA to
label: READ_REG_FILE
if Variable Remove not Equals TRUE
Read from Text File $SUPPORTDIR$\\RegistrySettings.txt into Variable REGISTRY_ENTRY (get EOF into REGISTRY_ENTRY_EOF)
Parse String $REGISTRY_ENTRY$ into Variables REGISTRY_TYPE and REGISTRY_ENTRY (Split at first occurrence of pattern)
Parse String $REGISTRY_ENTRY$ into Variables REGISTRY_KEY and REGISTRY_VALUE (Split at first occurrence of pattern)
Parse String $REGISTRY_VALUE$ into Variables REGISTRY_VALUE and REGISTRY_DATA (Split at first occurrence of pattern)
if Variable REGISTRY_TYPE Equals String
Write Registry Key HKCU\\$REGISTRY_KEY$\\$REGISTRY_VALUE$, $REGISTRY_DATA$
end
if Variable REGISTRY_TYPE Equals Int
Write Registry Key HKCU\\$REGISTRY_KEY$\\$REGISTRY_VALUE$, $REGISTRY_DATA$
end
if Variable REGISTRY_TYPE Equals Binary
Write Registry Key HKCU\\$REGISTRY_KEY$\\$REGISTRY_VALUE$, $REGISTRY_DATA$
end
if Variable REGISTRY_ENTRY_EOF Equals FALSE
GoTo Label: READ_REG_FILE
end
end



This looks to me like it should work, but when I run it, only the last line of the file is actually written to the registry. Does anyone know why this is?

Posted: Mon Sep 25, 2006 12:14 pm
by MichaelNesmith
This is because you cannot loop Windows Installer commands in the setup script - please read this whitepaper for information:

http://www.installaware.com/msicode_scr ... nology.pdf

Posted: Tue Sep 26, 2006 9:05 am
by tomriley
Thanks for that. Does anyone know a method of reading the registry values from a configuration file so that I don't have to import entries from my registry every time I make a change?

Posted: Tue Sep 26, 2006 12:54 pm
by MichaelNesmith
You can just merge a .reg file silently at install time.

Posted: Thu Oct 12, 2006 8:49 am
by tomriley
Thanks again. Any chance of a few pointers on how to do this? I've looked in the help and not managed to find anything.

Posted: Thu Oct 12, 2006 4:44 pm
by MichaelNesmith
Use Run Program with regedit to silently merge the .reg file with your registry. The silent parameter might be /s or /y - a quick Google search should reveal this information for you.