kinsells
Posts: 2
Joined: Fri Feb 03, 2006 7:24 am

Custom Actions - Again

Hi,

I am currently evaluating Advanced Installer 3.6.1 and am having difficulties inserting a custom action.

(I am completely new to vbscript and installations....)

I have read through the forum, and tried to apply them to my particular situation but to no avail.
I keep getting the "..problem with Windows Installer...script could not be run....contact package vendor...." error

The script runs up to a certain point and then fails....
i.e. I can see the script rename and delete the files in the directory before it fails...

What I need to do is...prompt the user for the type of database they are using, Access/SQL, and then rename some files in a directory based on this information....

I need to then register an ODBC connection for these...

My script is below;


[/img]

Code: Select all

set wshell=createObject("wscript.shell")


Const scatsTitle = "         SCATS Central Manager 6.5.2      "
Const installDir = "C:\Program Files\SCATS6\Central Manager"
dim dbManage
dim msAccess
dim access97

dbManage = msgBox("Do you have a Database Management System", 4+vbQuestion, scatsTitle)
if dbManage = vbYes then
	msAccess = msgBox("Are you you using MS Access?", 4+vbQuestion, scatsTitle)
	if msAccess = vbYes then
		access97 = msgBox("If you are using MS Access 97 click yes, otherwise click No", 4+vbQuestion, scatsTitle)
		if access97 = vbYes then
			setSCMSAccess97()
		else
			setSCMSAccess2000()
		end if
	else
		setSCMSSQL()
	end if
else
	setSCMSAccess97()
end if

function setSCMSAccess97()
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile installDir&"\New SCMS.mdb" , installDir&"\SCMS.mdb"
objFSO.DeleteFile(installDir&"\New SCMS 2000.mdb"), true
objFSO.DeleteFile(installDir&"\New SCMS.mdf"), true
objFSO.DeleteFile(installDir&"\New SCMS.ldf"), true
end function

function setSCMSAccess2000()
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile installDir&"\New SCMS 2000.mdb" , installDir&"\SCMS.mdb"
objFSO.DeleteFile(installDir&"\New SCMS.mdb"), true
objFSO.DeleteFile(installDir&"\New SCMS.mdf"), true
objFSO.DeleteFile(installDir&"\New SCMS.ldf"), true
end function


function setSCMSSQL()
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile installDir&"\New SCMS.mdf" , installDir&"\SCMS.mdf"
objFSO.MoveFile installDir&"\New SCMS.ldf" , installDir&"\SCMS.ldf"
objFSO.DeleteFile(installDir&"\*.mdb"), true
end function

I hope somone can help...

Thanks in advance,
Seán.
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

Since you did not specify any other information about this Custom Action (in what stage it is supposed to run, the Scheduling Option, Execution Condition etc), I have assumed the following:
- the files that need to be renamed/deleted are installed by your application (since you use the hard-coded "installDir" variable)
- thus, the Custom Action is scheduled after the files have been installed: I have used the "InstallFinalize" stage.

Although there are some issues regarding your script and the approach you are using, you will be surprised to know that it worked for me without error.

Some observations regarding this approach:
1. The "installDir" is hard-coded; if the user has installed your application in another folder, the script will fail. You should use something like:

Code: Select all

installDir = Session.Property("APPDIR")

' eliminate the trailing \
installDir = Left(installDir, Len(installDir) - 1) 
2. The application will fail to uninstall or repair properly because you are deleting/renaming files from within a script.

I am not quite sure what you are trying to achieve, but, instead of this approach, I would recommend that you put each one of the 3 file sets into a different folder with their final names ("SCMS.mdb" etc). Your Custom Action will only prompt the user and set a property depending on his selection. This property will be used subsequently to condition the installation of each of the 3 file sets.

If this is what you are trying to achieve, please let me know and I will give you more details.

Regards,
Denis
Last edited by Ionut on Mon Feb 06, 2006 5:07 pm, edited 1 time in total.
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
kinsells
Posts: 2
Joined: Fri Feb 03, 2006 7:24 am

Hi Denis,

Thank you for your reply, and your valuable tips. It would be great if you could outline how to do this...

I have tried running this again, but I am still getting the "script error"

I need to do the following;

- Install Files
- Rename New SCMS.* to SCMS.* (Or in fact select a folder)
- Register an ODBC Connection to the SCMS.* database.
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,
- Rename New SCMS.* to SCMS.*
If you rename the files after they have been installed, then they will not be removed on uninstall.

I would recommend a different approach. Consider the following scenario:

1. At the beginning of the setup process, the user will select which database file(s) to use. This will be done using an attached VBScript Custom Action (a modified version of the one you are using right now). This script will set a property (DBTOUSE) to one of the following values: "A97", "A2000" or "MSSQL".

2. In addition to the other Features of your package, you will need to create 3 more Features ("Access97", "Access2000" and "MSSQL" for example), one for each set of database files. Only one of these features will be installed, depending on the value of the "DBTOUSE" property set by the VBScript. Thus, it is not necessary to install the files and then rename/delete some of them based on the user selection - only the required files will be installed.

3. The final step would be to create 3 ODBC Data Sources (in the ODBC page of AdvInst) and put each one in the appropriate Feature ("Access97", "Access2000" or "MSSQL").


For now, I shall explain only the first 2 aspects presented above. These are the steps you should follow:

A. Outside of AdvInst, create 3 folders ("Access97", "Access2000" and "Mssql") and put each database file in the appropriate folder ("New SCMS.mdb" in the "Access97" folder, "New SCMS 2000.mdb" in the "Access2000" folder and the other 2 files in the "Mssql" folder). Rename all the files to their appropriate final names ("SCMS.*")

B. In the "Files and Folders" page of AdvInst, use the "Add Folder" toolbar button and add all the 3 folders created above to your package.

C. Switch to the Custom Actions page and make sure that the tree item "InstallInitialize" is visible under "InstallExecuteSequence" (if not, right click on "InstallExecuteSequence" and select "Show Standard Action -> Before File Installation -> InstallInitialize"). Then:

a) Right click on the "InstallInitialize" tree item and select "New Custom Action -> Directory Set with Formatted", then select the "Access97" folder you added in step A. In the "Formatted Text" field enter: [APPDIR]

b) Repeat step C.a) above for the other 2 folders ("Access2000" and "Mssql").

The purpose of these 3 Directory Set with Formatted Custom Actions is to redirect the contents of the 3 folders to the Installation Folder. Remember that only the file(s) from one of these folders will be installed.

D. Still in the Custom Actions page, make sure that the "Begin" tree item is visible under "InstallUISequence" (not "InstallExecuteSequence"). Then:

a) Create a new text file ("prompt.vbs") and copy the following code into it:

Code: Select all

Dim strDB

dbManage = msgBox("Do you have a Database Management System", 4+vbQuestion, scatsTitle)
if dbManage = vbYes then
   msAccess = msgBox("Are you you using MS Access?", 4+vbQuestion, scatsTitle)
   if msAccess = vbYes then
      access97 = msgBox("If you are using MS Access 97 click yes, otherwise click No", 4+vbQuestion, scatsTitle)
      if access97 = vbYes then
         strDB = "A97"
      else
         strDB = "A2000"
      end if
   else
      strDB = "MSSQL"
   end if
else
   strDB = "A97"
end if

Session.Property("DBTOUSE") = strDB
b) Right click on the "InstallUISequence -> Begin" item and select "New Attached Custom Action", then select the VBScript file you have created in the previous step.

c) The "Function Name" field will be left blank. Set the Execution Condition to: (Not Installed)

This Custom Action will display the message boxes and set the "DBTOUSE" property based on the user selection. The value of this property will be used subsequently to determine which database files to install.

E. Switch to the Organization page and create 3 new Features ("Access97", "Access2000" and "MSSQL"), then move the Components corresponding to the database files to the appropriate Feature. Therefore, the "Features and Components" tree control will look something like this:

Code: Select all

Product
  - MainFeature
      - ...
  - Access97
      - SCMS.mdb
  - Access2000
      - SCMS.mdb_1
  - MSSQL
      - SCMS.ldf
  - ...
For each of the 3 Features you have added, click the "Conditional" button at the right of the "Install Level" field and in the "Edit Conditional Levels" dialog, click the "New" button. Then set the Level to zero and the Condition to:
- for the Access97 Feature : (DBTOUSE <> "A97") AND (Not Installed)
- for the Access2000 Feature: (DBTOUSE <> "A2000") AND (Not Installed)
- for the MSSQL Feature : (DBTOUSE <> "MSSQL") AND (Not Installed)

Therefore, only one Feature will be installed depending on the value of the "DBTOUSE" property, which in turn depends on the user selection.

Hope this helps.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”