seppork
Posts: 15
Joined: Tue Jul 03, 2007 8:12 pm

How to put /'s or \\'s to an ini -file?

Hello!

I am trying to find out how to put forward slashes ( / ) or double backslashes ( \\ ) to an ini - file.

My application installs mySQL -server and starts the service. The my.ini is located in c:\windows !
This my.ini files uses two alternative syntaxes forward slash or double backward slashes:

[some section]
c:/program files/myApp/myDB ...
or
c:\\program files\\myApp\\myDB ...

I have tried editing the init entry as follows :
[ProgramFilesFolder]/MyApp/MyEntry
but
The my.ini file content will be : c:\program files\/MyApp/MyEntry
this will not work for obvious reasons...

Is there a way to replace the '\' .s with '/' .s or '\\' .s in the formatted types?

Regards
SeppoRK
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to put /'s or \\'s to an ini -file?

Hi,

Please note that you can use a custom action which replaces the "\" characters with "/". Here is a sample VBScript:

Code: Select all

'declare the variables
Dim path
Dim modifiedPath
Dim tokens

'get the path you want to modify
path = Session.Property("ProgramFilesFolder")
'append a special character to the path
'so we can determine its end
path = path & "$"

'get the folder names from the path
tokens = Split(path,"\", -1)

'construct the modified path
'by using the folder names and "/"
i=0
modifiedPath = ""
Do While tokens(i) <> "$"
  modifiedPath = modifiedPath & tokens(i) & "/"
  i = i + 1
Loop

'place the modified path into a property
Session.Property("MOD_ProgramFilesFolder") = modifiedPath
This custom action can be added as an Attached custom action under "InstallExecuteSequence" -> "CostFinalize". Note that it should be added as Immediate in order to access installer properties. Also, the "Function Name" field in the Custom Action Properties page should be empty.

After the custom actions runs, the "MOD_ProgramFilesFolder" property will contain the path of the "Program Files" folder, but with slashes ("/"). For your example, you could use this path:

Code: Select all

[MOD_ProgramFilesFolder]MyApp/MyEntry 
and it will be resolved to:

Code: Select all

c:/program files/MyApp/MyEntry
Please note that you can modify the custom action in order to replace "\" with any characters (for example with "\\").

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
seppork
Posts: 15
Joined: Tue Jul 03, 2007 8:12 pm

Re: How to put /'s or \\'s to an ini -file?

Thanks Cosmin !

The solution works fine!
I would never had found out the solution - this saves me a considerable amout of work!

Regards
Seppo RK
Trax
Posts: 46
Joined: Wed May 06, 2009 5:24 pm

Re: How to put /'s or \\'s to an ini -file?

Hello,

I am trying to do this exact thing now but am using version 10.0 and it seems the Custom Action UI is different.

How am I able to accomplish this same thing in the new version?

Thanks
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: How to put /'s or \\'s to an ini -file?

Hello,

If you are using Advanced Installer 10.0, you have to use a "Launch attached file" custom action for launching the VBS script file, configured to run on "Immediately" execution time. The "Function" field in the "General Properties" section should be left empty.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Trax
Posts: 46
Joined: Wed May 06, 2009 5:24 pm

Re: How to put /'s or \\'s to an ini -file?

It still does not seem to be working.

I should also mention that In my project I have a Text file Update that needs this modified property so that it can update a properties file installed by the program. Is that possible? Which order do does the Custom Action need to be in?

Below is the code I am using in vbs

Code: Select all

'declare the variables
Dim path
Dim modifiedPath
Dim tokens

'get the path you want to modify
path = Session.Property("resources_1_Dir")
'append a special character to the path
'so we can determine its end
path = path & "$"

'get the folder names from the path
tokens = Split(path,"\", -1)

'construct the modified path
'by using the folder names and "\\"
i=0
modifiedPath = ""
Do While tokens(i) <> "$"
  modifiedPath = modifiedPath & tokens(i) & "\\"
  i = i + 1
Loop

'place the modified path into a property
Session.Property("MOD_resources_1_Dir") = modifiedPath
Trax
Posts: 46
Joined: Wed May 06, 2009 5:24 pm

Re: How to put /'s or \\'s to an ini -file?

Thanks for your help. I got it to work.
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: How to put /'s or \\'s to an ini -file?

Hello,

You are welcome!
I'm glad that you've sorted things out.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”