cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Not applicable

Rename File Before Installation

Hello from greece 🙂

gays my brain has been fried!!!
please explain me how to do that...
first of all iam newbe to install shield 2009
i have make a simple .msi setup and i want
to keep a backup of 1 file before the installation begin.
so 3 ways!
1) rename the old file during the installation
and when i will unistall it rename it again to the original name
2) move the file to a backup folder and with unistall restore it to the original path
3) I can include that original file(that i want to backup) into my setup.exe BUT INSTALL IT only when the unistallation process begin. I mean the unistall to install that original file and restore it.

please iam not expert in scripts, but iam trying hard to untrestant all those functions and how to import them...

i have found in fag a script

RenameFile Example 
InstallShield 2009 » InstallScript Language Reference


Note

To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the RenameFile function.

*

* First, RenameFile is called to rename FILENAME1 to FILENAME2.

* It is then called again to move the FILENAME2 file to the

* TARGET directory.

*

* This can also be done in one call to RenameFile. The third

* call to RenameFile demonstrates this by renaming and moving

* the FILENAME2 file from the TARGET directory to the SOURCE

* directory, with the FILENAME1 file name.

*

* Note: Before running this script, set the preprocessor

* constants so that they specify valid file names and

* paths on the target system.

*

\*--------------------------------------------------------------*/


#define FILENAME1 "ISExampl.txt"

#define FILENAME2 "ISExampl.bak"

#define SOURCE_DIR "C:\\ISExampl\\Source"

#define TARGET_DIR "C:\\ISExampl\\Target"

#define TITLE "RenameFile Example"



#include "ifx.h"


function OnBegin()

begin


// Set up system variables for rename operation.

SRCDIR = SOURCE_DIR;

TARGETDIR = SOURCE_DIR;


// Rename FILENAME1 to FILENAME2.

if (RenameFile (FILENAME1, FILENAME2) < 0) then

MessageBox("First call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully renamed to %s.";

SprintfBox(INFORMATION, szTitle, szMsg, FILENAME1, FILENAME2);

endif;


// Set up system variables to move a file from one directory to another.

SRCDIR = SOURCE_DIR;

TARGETDIR = TARGET_DIR;


// Move the file from the SOURCE to the TARGET directory.

if (RenameFile(FILENAME2, FILENAME2) < 0) then

MessageBox("Second call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully moved to %s.";

SprintfBox(INFORMATION, TITLE, szMsg, FILENAME2, TARGETDIR);

endif;


// Set up system variables to move the file back to its original location.

SRCDIR = TARGET_DIR;

TARGETDIR = SOURCE_DIR;


// Rename the file and move it from the TARGET directory

// to the SOURCE directory.

if (RenameFile(FILENAME2, FILENAME1) < 0) then

MessageBox("Third call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully renamed %s and moved to the directory %s.";

SprintfBox(INFORMATION, TITLE, szMsg, FILENAME2, FILENAME1, TARGETDIR);

endif;


end;


but i dont know how to execute that script
THANK YOU FOR YOUR TIME!!!
Labels (1)
0 Kudos
(4) Replies
Not applicable

i have fount it!
firts step is ok... i have used movefile from table editor
WHEN I INSTALLING THE SETUP the original file msd.dll is renaming to backup_msd.dll
BUT HOW ILL RESTORE IT BACK WHEN I UNISTALL THE PROGRAM?
HERE I WANT YOUR HELP ladies...

on unistall to rename the file backup_msd.dll to original msd.dll
0 Kudos
ChandanOmkar
Level 8

on the MaintUIAfter() event of your installscript, rename the file to its original name. This event is called during uninstallation.
0 Kudos
Not applicable

Please explain how to use that function, i have to insert it in the custom actions like a installscript action?

i have make some scripts.rul see the photo here... but what iam doing wrong?
HERE IS THE CODE:

#define FILENAME1  "0000001.lan" 

#define FILENAME2 "BACKUP-0000001.lan"

#define SOURCE_DIR "C:\\Battlestations Midway\\lockit"

#define TARGET_DIR "C:\\Battlestations Midway\\lockit"

#define TITLE "RenameFile Example"

#include "ifx.h"


function OnMaintUIAfter()
STRING szMsg, szTitle;

begin
// Set up system variables for rename operation.

SRCDIR = SOURCE_DIR;

TARGETDIR = SOURCE_DIR;

// Rename FILENAME1 to FILENAME2.

if (RenameFile (FILENAME1, FILENAME2) < 0) then

MessageBox("First call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully renamed to %s.";

SprintfBox(INFORMATION, szTitle, szMsg, FILENAME1, FILENAME2);

endif;


// Set up system variables to move a file from one directory to another.

SRCDIR = SOURCE_DIR;

TARGETDIR = TARGET_DIR;


// Move the file from the SOURCE to the TARGET directory.

if (RenameFile(FILENAME2, FILENAME2) < 0) then

MessageBox("Second call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully moved to %s.";

SprintfBox(INFORMATION, TITLE, szMsg, FILENAME2, TARGETDIR);

endif;


// Set up system variables to move the file back to its original location.

SRCDIR = TARGET_DIR;

TARGETDIR = SOURCE_DIR;


// Rename the file and move it from the TARGET directory

// to the SOURCE directory.

if (RenameFile(FILENAME2, FILENAME1) < 0) then

MessageBox("Third call to RenameFile failed.", SEVERE);

abort;

else

szMsg = "%s successfully renamed %s and moved to the directory %s.";

SprintfBox(INFORMATION, TITLE, szMsg, FILENAME2, FILENAME1, TARGETDIR);
endif;
end;




NOW WHAT IS THE NEXT STEP?
INSERT A CUSTOM ACTION LIKE INSTALLSCRIPT?
AND INSERT IT THEN INTO EXECUTE SEQUENSE?
0 Kudos
Not applicable

OK MY BRAIN HAS BEEN FAIRD LADIES!!!
BUT WE HAVE SUCCESS!!!
HERE IS MY SOLUTION...
1) Use the movefile from the Direct Editor to rename your file during the installation process! its easy...
2) Go to InstallScript and right click make 1 new script. rENAME THE SCRIPT "Setup.rul" and the function folder should be "MyFunction"
then copy paste this code into the script

////////////////////////////////////////////////////////////////////////////////
//
// IIIIIII SSSSSS
// II SS InstallShield (R)
// II SSSSSS (c) 1996-2002, InstallShield Software Corporation
// II SS All rights reserved.
// IIIIIII SSSSSS
//
//
// This template script provides the code necessary to build an entry-point
// function to be called in an InstallScript custom action.
//
//
// File Name: Setup.rul
//
// Description: InstallShield script
//
////////////////////////////////////////////////////////////////////////////////

// Include Ifx.h for built-in InstallScript function prototypes, for Windows
// Installer API function prototypes and constants, and to declare code for
// the OnBegin and OnEnd events.
#include "ifx.h"

// The keyword export identifies MyFunction() as an entry-point function.
// The argument it accepts must be a handle to the Installer database.
export prototype MyFunction(HWND);

// To Do: Declare global variables, define constants, and prototype user-
// defined and DLL functions here.


// To Do: Create a custom action for this entry-point function:
// 1. Right-click on "Custom Actions" in the Sequences/Actions view.
// 2. Select "Custom Action Wizard" from the context menu.
// 3. Proceed through the wizard and give the custom action a unique name.
// 4. Select "Run InstallScript code" for the custom action type, and in
// the next panel select "MyFunction" (or the new name of the entry-
// point function) for the source.
// 5. Click Next, accepting the default selections until the wizard
// creates the custom action.
//
// Once you have made a custom action, you must execute it in your setup by
// inserting it into a sequence or making it the result of a dialog's
// control event.

///////////////////////////////////////////////////////////////////////////////
//
// Function: MyFunction
//
// Purpose: This function will be called by the script engine when
// Windows(TM) Installer executes your custom action (see the "To
// Do," above).
//
///////////////////////////////////////////////////////////////////////////////
#define TARGET INSTALLDIR

function MyFunction(hMSI)
// To Do: Declare local variables.
begin

if( RenameFile(TARGET^"lockit\\0000001.lan",TARGET^"lockit\\deutsch_0000001.lan") == 0) then
MessageBox("success",INFORMATION);
else
MessageBox("fail",INFORMATION);
endif;

// To Do: Write script that will be executed when MyFunction is called.

end;


3) then go to Custom Actions
right click select make new custom action wizard..
then select run install script--->next---> select "MyFunctions"---> and then next next next next finish...
4) put your Custom Action into the execute sequance in what position you want.
i have put it last in the sequence.
5) Select your new custom Actiom and Put a contition to your new custom action Remove="All" (if you want that Cutom action to execute it only during the uninstallation process).

enjoy!!!:mad:

PLEASE SOMEBODE CAN CONFIRM THAT ALL THE ABOVE ARE OK?
iam doing anything xrong?
0 Kudos