Page 1 of 1

Runtime import reg file

Posted: Sat Jun 12, 2010 5:50 pm
by rasmusw
I would like to be able to provide the customer with the ability to configure some program defaults which should be configured in the registry when my program installs using Group Policy.

I would like to have the installer check for a .reg file located in the same folder as the installer executable, and if the installer sees the file, it would import the settings.
Unfortunately there seems to be no way to programmatically import .reg files. Is that correct? Did I miss it somewhere in the docs?

Instead I decided to do it like this:

Code: Select all

    
Set Variable REGFILENAME to 
Find All Files in path $GPOPATHVAR$\Setup-MobilePBX.reg, write result into variable REGFILENAME
if Variable REGFILENAME not Equals 
   Run Program reg /import $REGFILENAME$
end
I added the lines above immediately before the "Apply Install" command.

It doesn't seem to run the program, and the result variable from the Run Program command has the value 259.
The "reg" command is in the path on the test computer, and the "reg /import settings.reg" command works fine when executed manually.

The installation log contains the REGFILENAME variable with the correct filename and path, but I can't see anywhere where it tries to run the command.

How can I debug the problem to figure out why it doesn't run the program?
Or maybe there is a much better way for the customer to provide a settings file which the installer can import (without a lot of parsing INI files etc.)

Re: Runtime import reg file

Posted: Sat Jun 12, 2010 6:52 pm
by MichaelNesmith
Try specifying the full path to reg.
Also try enclosing the returned file name inside double quotes.
Easiest way to test would be to replace reg with a program that displays the exact list of command line parameters it has been sent.

Re: Runtime import reg file

Posted: Sun Jun 13, 2010 1:49 am
by rasmusw
Ah yes, the program which logs all command line parameters gave me an indication of the problem.
The program I created was a cmd-file with the following contents:

Code: Select all

@echo off
echo %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 > logcall.txt
It resulted in this output:

Code: Select all

"C:\DOCUME~1\testuser\LOCALS~1\Temp\logcall.cmd" import "\intern\public\msi\test\Setup-Program.reg"
Note the single backslash in the beginning of the file to import.
I also added a Write Registry command in the script which wrote the value of my reg-file path variable to a registry string value. That value does contain two backslashes. The setup log file also contains the correct path everywhere.
So apparently strings which begin with double backslashes are cut short when used as command line parameter.

I changed my execution code to work around this problem by replacing all backslashes in the string with two backslashes:

Code: Select all

if Variable REGFILENAME not Equals 
  Replace \ with \\ in variable REGFILENAME
  Run Program $TEMPDIR$\logcall.cmd import "$REGFILENAME$" (WAIT, get result into variable RUNRESULT)
  Write Registry Key HKCU\Software\Productname\REGFILENAME, $REGFILENAME$
  Run Program $WINSYSDIR$\reg.exe import "$REGFILENAME$"
end
This now works. But there is some strange behaviour still.
  1. The Replace String command is set to replace all occurrences of \ with \\. But it only replaces once. So the string written to the registry (as well as the setup log file) contains an initial three backslashes, but all the following backslashes are single.
  2. The program is executed, but there is no mention of it in the setup log file
The main thing is that it works with the Replace String workaround.

Re: Runtime import reg file

Posted: Sun Jun 13, 2010 5:05 pm
by MichaelNesmith
Run Program does not get logged, the setup log contains the results of a call to Apply Changes along with some diagnostic information.

I am glad you got it working :) I think you'd have had an easier time without the back-slashes if you used full paths instead of relative ones, but I don't really understand all the stuff about the program you created (is it a cmd script?) so just glad to hear you got it working :D

Re: Runtime import reg file

Posted: Mon Jun 14, 2010 12:13 am
by rasmusw
The back-slashes don't indicate a relative path, it's a complete UNC network path.
That was what caused the problem - a UNC path begins with two back-slashes, and for some reason the Run Program command removes one of them (at least that's what it looks like to me).

As I mentioned in my first post, this is to be a group policy installer, so it will necessarily run from a network location. Using GPOPATH (with the GPOPATHVAR workaround), I get the location of the MSI file currently running, and look for a file in the same folder. The full path of that file is passed as a parameter to the Run Program command.