View Full Version : Can I read an ascii file in vbscript custom action ?

02-22-2011, 09:16 AM
I have a txt file from which I have to read some lines but I get an error.

The vbscript works well if it is started from Win7 but I get an error starting int from IS2011Express.

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFileRead = fso.OpenTextFile("c:\mydir\testfile.txt", 1)
MyLine = MyFileRead.ReadLine

Anyone have an idea ?

02-22-2011, 02:03 PM
Your VBScript works on my side. I can run it successfully from a setup created in InstallShield 2011 Express. Can you provide more details about the error? I am also curious what type of custom action you are using and where you sequence your action.

02-23-2011, 05:37 AM

I have done an error in my vbs. Extracting the lines for this thread I have correct the error.

Now can write and read the file.

I write the file with some "Properties" in "After Ready to install" and I use them
in "After file transfer", where the properties are not available.

Do you think there is a better way to get properties "After file transfer" ?

'script to write the properties in a file
Set fso = CreateObject("Scripting.FileSystemObject")
Set TmpFolder = fso.CreateFolder("c:\MyDir")
Set MyFile = TmpFolder.CreateTextFile("testfile.txt", True)
MyFile.WriteLine( Session.Property("INSTALLDIR") )
MyFile.WriteLine( Session.Property("DATABASEDIR") )
MyFile.WriteLine( Session.Property("SourceDir") )

'script to read the properties in a file
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\\MyDir\\testfile.txt", 1)
TheLine = MyFile.ReadLine
TheLine = MyFile.ReadLine
TheLine = MyFile.ReadLine

02-23-2011, 01:34 PM
The C:\ drive may not be available on all of your target machines. I would use the Windows temporary directory instead of creating the C:\MyDir folder as follows:

Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2

Set fso = CreateObject("Scripting.FileSystemObject")
Set TmpFolder = fso.GetSpecialFolder(TemporaryFolder)
Set MyFile = TmpFolder.CreateTextFile("testfile.txt", True)

Also, the custom action at the "After Ready to install" location will not be executed for silent installations. If it is a problem, you may want to consider upgrading to InstallShield Pro or Premier edition. The Express edition does not have the ability to create immediate custom actions in the Exec Sequence.

02-24-2011, 05:28 AM
I have changed my vbs file and now I use the windows temporary directory.
Thank you for your support.

I have another question about IS2011express and Crystal report for VS2010.
The msm for CR doesn't install in Win7.
Reading the forums I have found some suggestion and now I run 2 custom action at "After install Welcome" to install "VC2005redist.exe" and "VC2005Redist.exe for ATL".
Without these files installed before proceed with the installation the CR mcm setup do an error when registering the dll.
Including the provided "Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)" instead of the 2 microsoft .exe bootstapper doesn't solve the problem.
Have you any suggestion ?