Renaming a file during or after install. - Advanced Installer Community
dan_gribble
Posts: 2
Joined: Mon Dec 02, 2013 4:13 pm

Renaming a file during or after install.

Hi,

I would like to give users the option to rename a file installed as part of an MSI I have created, either during or after the install has completed.

As the user can alter the installation path before installing, is there a way (if so how?) to extract the contents of [APPDIR] and pass them as a parameter to a VBScript or .exe, .bat etc file.

Thank you.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Renaming a file during or after install.

Hello and welcome to Advanced Installer forums,

I'm afraid we don't have predefined support for this.

However, you can achieve this through your own custom action. For example, you can use the C++ approach to rename the related file; you can take a look on the rename function.
Then you can go in the “Custom Actions” page and add a predefined Launch attached file custom action with sequence. This type of custom action can execute an application (EXE or DLL) or run a script (VBScript or Java script). Also, the source file will be embedded in the MSI file but will not be deployed at install time with the other application files.

Also, you can use a .bat file which will execute the ren or rename command line. In order to launch your .bat file you can follow the steps which are described in the launch a CMD or BAT file article.
In the command line field of the launch file custom action you can have something like:
"[APPDIR]myFile.txt" "[CUSTOM_NAME].txt" where:
  • -[APPDIR]myFile.txt - the file which I want to rename
    - [CUSTOM_NAME].txt - this is the value of the public property assigned to the edit field where the user can choose the custom name
This custom action should be added after the Install Execution Stage >> Add Resources stage.

Please keep in mind that during an uninstall, Windows Installer removes only the data registered into the MSI file. All other data created by custom actions, by the installed application or by the user is not registered in the MSI, therefore it will not be removed.

Let us know if that helped, otherwise give us more details about your specific scenario.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
dan_gribble
Posts: 2
Joined: Mon Dec 02, 2013 4:13 pm

Re: Renaming a file during or after install.

Thanks Dan, knowing you can supply [APPDIR] as part of parameter is really useful (it's actually what I really wanted to).

Can you also supply that as a parameter to a VB Script (if so how)? As I really don't want to have a .BAT or .CMD script left hanging around after install.

The documentation is not that clear on supplying parameters when calling DLL's VBScripts etc.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Renaming a file during or after install.

Hello,

In order to achieve that you can use a .vbs file which can have the following code:

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")

name = Session.Property("APPDIR") & "myFile.txt"

cstName = Session.Property("CST_NAME")

APPDIR_PATH = Session.Property("APPDIR")

objFSO.MoveFile name , APPDIR_PATH & cstName & ".txt"
where:
  • myFile.txt - the file to be renamed
    CST_NAME - is the public property assigned to the edit field where the user can input the custom name for the related file.
In order to launch your .vbs file, you can go in the Custom Actions page and add a predefined Launch attached file custom action with sequence. This way, the source file will be embedded in the MSI file but will not be deployed at install time with the other application files. You should scheduled this custom action between the InstallExecute and InstallFinalize standard actions. Also, in the Install Parameters page you should enable the Run as administrator option.

If you have other questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”