cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DLee65
Level 13

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
Level 7

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
Level 13

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
Level 13

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
MichaelU
Level 12 Flexeran
Level 12 Flexeran

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
Level 4

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
Level 13

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
Level 4

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
Level 9

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

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
rrinblue22
Level 9

This code here should get you through.... and I assume you have a Basic MSI project type.

[CODE]export prototype set_prop(HWND);

function set_prop(hMSI)

STRING tmpINSTALLDIR;
STRING svInstalldir[256];
NUMBER nBuffer;

begin

tmpINSTALLDIR = INSTALLDIR;
nBuffer = 256;
StrRemoveLastSlash(tmpINSTALLDIR);
MsiSetProperty(hMSI,"DOUBLE_INSTALLDIR",tmpINSTALLDIR);

end;[/CODE]
0 Kudos
RatBoyGL
Level 4

Thanks.

I will try it.

Do I need another new property though to store the final value in?

Or do I change this: Session.Property("DOUBLE_INSTALLDIR") = Replace( Session.Property("INSTALLDIRNOTRAIL"), "\", "\\" )

To this: Session.Property("DOUBLE_INSTALLDIR") = Replace( Session.Property("DOUBLE_INSTALLDIR"), "\", "\\" )
0 Kudos
rrinblue22
Level 9

Nope not necessary ... you can still have one property DOUBLE_INSTALLDIR and perform all the actions (remove the trailing slash, remove double slash) on it.
0 Kudos
RatBoyGL
Level 4

Well, that didnt work either.

I keep getting the attached error when running the .MSI.



It is referencing my custom action which has this code: Session.Property("DOUBLE_INSTALLDIR") = Replace( Session.Property("DOUBLE_INSTALLDIR"), "\", "\\" )

But that did work when the replace statement was replacing just INSTALLDIR.

LOL...
0 Kudos
rrinblue22
Level 9

Appears to be a problem with the custom action sequence.


1: Run the InstallScript Custom action and result is DOUBLE_INSTALLDIR property is loaded with INSTALLDIR value without trailing slash.
2: Run your custom action which does "\\" to "\" on DOUBLE_INSTALLDIR property
0 Kudos
RatBoyGL
Level 4

rrinblue22 wrote:
Appears to be a problem with the custom action sequence.


1: Run the InstallScript Custom action and result is DOUBLE_INSTALLDIR property is loaded with INSTALLDIR value without trailing slash.
2: Run your custom action which does "\\" to "\" on DOUBLE_INSTALLDIR property



Yea, that is what I am doing:

0 Kudos
rrinblue22
Level 9

you can also just write one single VBScript which performs both task of removing the trailing slash and "\\" to "\".
just a suggestion to un-complicate things 🙂
0 Kudos
RatBoyGL
Level 4

Well..

Now I am closer than ever before.

Now it is kind of working, however, my config file ends up with two rows:




Thank you for all the help though. I am now almost there.

I guess in the XML Editor I can add a remove line to remove the bad one? Not sure why I should have to do that though.
0 Kudos
rrinblue22
Level 9

I have just sent an email to your RatBoyGL account here.
0 Kudos
RatBoyGL
Level 4

Replied.

ROFL...
0 Kudos
RatBoyGL
Level 4

Here is what I have in the XML Editor:



It is obviously adding the row for DOUBLE_INSTALLDIR which is now the one without double slashes and no trailing.

But where the other row with the trailing slashes is coming from is boggling my mind.
0 Kudos