tjeziorny
Posts: 4
Joined: Fri Jan 20, 2006 4:44 pm

Custom Actions don't run

Hi,

I've created two .vbs files. One to retrieve the drive letter of a user's cd rom drive and write it to a properties file. The other to change all the backslashes in the properties (ini) file I'm dynamically creating into forward slashes so that my java app can read the paths.

I've attached these two files as custom actions (source type: .vbs/no function name/synchronous execution - ignore return code/immediate execution/always execute/Condition: NOT installed) to the "install finalize" standard action. The install kit builds correctly but when it's finished running the files the scripts should change remain the same.

Both scripts work fine when I run them manually.

Any ideas what I'm doing wrong?

Thanks,

Tom
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

Windows Installer runs script Custom Actions directly and does not use the Windows Script Host. The WScript object cannot be used inside a script Custom Action because this object is provided by the Windows Script Host. Objects in the Windows Script Host object model can only be used in custom actions if Windows Script Host is installed on the computer by creating new instances of the object, with a call to CreateObject, and providing the ProgId of the object (for example "WScript.Shell"). Depending on the type of script Custom Action, access to some objects and methods of the Windows Script Host object model may be denied for security reasons.

For example, in a VBScript that is not used as a Custom Action and is run using "cscript.exe" or "wscript.exe" you would use:

Code: Select all

set WshShell = WScript.CreateObject("WScript.Shell")
However, in a VBScript that will be used as a Custom Action, you have to use something like this:

Code: Select all

set WshShell = CreateObject("WScript.Shell")
Also, you can not pass arguments to a VBScript CA. In an immediate Custom Acton, you can use Windows Installer Properties for this purpose. You can set a Property with:

Code: Select all

Sesssion.Property("PROPERTY") = "Value"
and retrieve the value of a Property with:

Code: Select all

strProperty = Sesssion.Property("PROPERTY")
If you have any problems, please post the scripts and I will tell you what needs to be changed.

Regards,
Denis
Last edited by Ionut on Fri Mar 17, 2006 2:58 pm, edited 2 times in total.
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
tjeziorny
Posts: 4
Joined: Fri Jan 20, 2006 4:44 pm

Tried adding the line you suggest and still no joy. Here is one of the scripts I'm trying to run:

Code: Select all

Set oShell = CreateObject("WScript.Shell")
	
	Const ForReading = 1
	Const ForWriting = 2
	
	strOldText = "\"
	strNewText = "/"
	strFile = ""
	
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile("app.properties", ForReading)
	
	strText = objFile.ReadAll
	objFile.Close
	strFile = Replace(strText, strOldText, strNewText)
	
	Set objFile = objFSO.OpenTextFile("app.properties", ForWriting)
	objFile.WriteLine strFile
	objFile.Close
	
	strText = ""
	strFile = ""
	
	Set objFile = objFSO.OpenTextFile("db.properties", ForReading)
	
	strText = objFile.ReadAll
	objFile.Close
	strFile = Replace(strText, strOldText, strNewText)
	
	Set objFile = objFSO.OpenTextFile("db.properties", ForWriting)
	objFile.WriteLine strFile
	objFile.Close
Any help would be appreciated!

Thanks
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

There is only one problem with this script: you need to set the working directory to the folder that contains the files "app.properties" and "db.properties" before calling the "OpenTextFile" method. If these files are located in the installation folder, you need to set the current directory to the value of the APPDIR property.

Therefore, you need to add the following lines to your script:

Code: Select all

Set oShell = CreateObject("WScript.Shell")
   
' Get the installation directory
strAppDir = Session.Property("APPDIR")

' Set the current directory to APPDIR
oShell.CurrentDirectory = strAppDir

.
.
.
A modified version of your script is presented below:

Code: Select all

Set oShell = CreateObject("WScript.Shell")
   
' Get the installation directory
strAppDir = Session.Property("APPDIR")

' Set the current directory to APPDIR
oShell.CurrentDirectory = strAppDir

strOldText = "\"
strNewText = "/"

ReplaceInFile "app.properties", strOldText, strNewText
ReplaceInFile "db.properties",  strOldText, strNewText

Function ReplaceInFile(strFileToUse, strOldText, strNewText)
	Const ForReading = 1
	Const ForWriting = 2
	
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFileToUse, ForReading)
	
	strText = ""
	strFile = ""
	
	strText = objFile.ReadAll
	objFile.Close
	strFile = Replace(strText, strOldText, strNewText)

	Set objFile = objFSO.OpenTextFile(strFileToUse, ForWriting)
	objFile.WriteLine strFile
	objFile.Close
End Function
Hope this helps.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
tjeziorny
Posts: 4
Joined: Fri Jan 20, 2006 4:44 pm

It worked!!!

Thanks!

Return to “Common Problems”