cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
DLee65
Pilgrim

Text file changes for registry files that include path statements

I have included in my installation a .REG file that needs to be modified by the installer.
I have setup the text file replacement set and all works except for one thing, cases where the file includes a path statement.

For instance one name is 'InstallPath'='{InstallPath}'. This is the value I place as the 'Find What' value.
For the Replace with value I have "InstallPath"="[INSTALLDIR]"

After the app is installed the value reads: "InstallPath"="C:\Program Files\Amazing Charts\"
The problem here is that the .reg file expects double slashes. The path above should read "C:\\Program Files\\AmazingCharts\\"
I thought about inserting a step to replace single slashes with double slashes but that would break the hive path which uses single slashes.

Is there a way to handle this situation so that my .reg file is updated correctly?
Does the text file Find What filter utilize regular expressions at all?

Do I need to pass this process off to an InstallScript or C# custom action to update the file properly?

Thank you.
Labels (1)
0 Kudos
20 Replies
TurboFisch
Pilgrim

Re: Text file changes for registry files that include path statements

I stopped using reg files for that reason. I just add the registry entry in the component's registry and set things like InstallLocation=[INSTALLDIR]
0 Kudos
DLee65
Pilgrim

Re: Text file changes for registry files that include path statements

Thank you for the input.

What I am trying to avoid is the installer executing just to write registry entries as a new user starts the application.
I am also trying to avoid having to touch NTUSER.DAT to handle the process.

I was hoping I could leverage the HKLM\Software\Microsoft\Active Setup key to write the key during login for each user.
0 Kudos
DLee65
Pilgrim

Re: Text file changes for registry files that include path statements

I decided to create a vbscript custom action that will handle this process. It is scheduled for deferred execution after the event for updating the text files.
basically it does a replace for '\' to '\\' for all patterns that match ^Chr(34), basically a line that begins with a single quote character.
I then append all text to a variable and after reading through file, close the file, open the file for writing and then write the variable to file, essentially overwriting the original file.

This achieves our goals to eliminate the need for 'repair' to run for each new user that starts our application.
0 Kudos
Flexera MichaelU
Flexera

Re: Text file changes for registry files that include path statements

Rather than making a custom action that updates a file, I think it would be less work and thus safer to make a custom action that updates a copy of INSTALLDIR, say creating the double-backslash version in INSTALLDIR_REGFILE, and referencing INSTALLDIR_REGFILE instead of INSTALLDIR in text file changes.
0 Kudos
RatBoyGL
Pilgrim

Re: Text file changes for registry files that include path statements

I am having the same issue with trying to edit an XML .config file.

The file, by default, has a file path with double slashes.

If I set it to INSTALLDIR in the red outlined box, it just puts the install path with single slashes instead of double.

Can anyone advize a way around this?

0 Kudos
DLee65
Pilgrim

Re: Text file changes for registry files that include path statements

You are going to have to do what Michael suggested.
1. Create a new custom action that sets a new property like INSTALLDIR_DBLSEPARATOR and use this property for modifying your XML file.

I would use a simple vbscript as the custom action and use the Session.Property("INSTALLDIR").

Example:

DIM propertyValue: propertyValue = Session.Property("INSTALLDIR")
DIM dlbSeparatorValue

dlbSeparatorValue = Replace(propertyValue, "\", "\\")
Session.Property("INSTALLDIR_DLBSEPARATOR") = dblSeparatorValue


I have NOT tested this code and I do not know if you need to escape the backslash, but this is the essence of what you need to do.

Then in your xml replace sequence use the property [INSTALLDIR_DBLSEPARATOR].

Hopefully this helps.

EDIT: You may want to use a regular expression too to test if the path already has double backslash, such as server paths, if that is even relevant to your case. Just thought I would bring it up just in case :). There are tons of examples of vbscript and regexp cases online if you get stuck.
0 Kudos
RatBoyGL
Pilgrim

Re: Text file changes for registry files that include path statements

DLee65.

I did something very close to this and now I am very close to having this fixed.

The problem now is, it is writing the path with a trailing \\ because INSTALLDIR has a trailing \

But in the config file I am editing, there is no trailing \

Not sure if there is a way to tell it to not put the trailing \\.

I have read this which has two different codes to remove the trailing backslash from InstallDir but I am not fluent enough in InstallShield to know how to implement this. https://flexeracommunity.force.com/customer/articles/en_US/HOWTO/Q106587
0 Kudos
rrinblue22
Pilgrim

Re: Text file changes for registry files that include path statements

You would just use "StrRemoveLastSlash" InstallScript function to remove the trailing slash from the path.
0 Kudos
RatBoyGL
Pilgrim

Re: Text file changes for registry files that include path statements

So if I use this code:

[CODE]function set_prop()
STRING tmpINSTALLDIR;
STRING svInstalldir[256];
NUMBER nBuffer;

begin
tmpINSTALLDIR = INSTALLDIR;
nBuffer = 256;
StrRemoveLastSlash(tmpINSTALLDIR);
MsiSetProperty(ISMSI_HANDLE,'INSTALLDIR',tmpINSTALLDIR);
end[/CODE]

I have a few noob questions:

1) Do I just create a custom action and put this in?

2) If I remove the trailing back slash, are there ramifications elsewhere in the project that I need to account for?

3) How come when I add this InstallScript to my other scripts, it is not select-able when donig a new custom action based on install script? It doesn't appear in the drop down menu there.

Man this should not be this hard just to remove a back slash.

Right now, I have a custom action doing this: Session.Property("DOUBLE_INSTALLDIR") = Replace( Session.Property("INSTALLDIR"), "\", "\\" )

That is to make DOUBLE_INSTALLDIR have the value of INSTALLDIR with double slashes and it is working. But putting the trailing \\ on the end, which my config files do not have.
0 Kudos