Luc Michel
Posts: 14
Joined: Tue Nov 22, 2005 5:06 pm

Script could not be run

Hello,

I have an error message when I test my install program. It append text to a file OK but create an error message. I have include this Custom Action : I am willing to upgrade my software and Maintenance plan to get support :

The use of this install program is to append many thousands line of text to an AutoCAD .pat file. Can you help step by step.

' EditPreferences.vbs
' Sample VBScript to write to a file.
' Author Guy Thomas http://computerperformance.co.uk/
' Ezine 79 Version 2.4 - July 2005
' -------------------------------------------------------------'

Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "c:\Ezine"
strFile = "\GuySays.txt"
strText = "Edit your Ezine Preferences"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If

set objFile = nothing
set objFolder = Nothing

' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

' Key Section to write the strText to the file.
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close

' Guy's idea for testing your script.
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If

WScript.Quit

' End of VBScript to write to a file
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi Luc,

Note that the installer runs script Custom Actions directly and does not use the Windows Script Host. Therefore, the WScript object cannot be used inside a script Custom Action because this object is provided by the Windows Script Host.

Hence, you cannot use "WScript.Echo" and "WScript.Quit" in a script Custom Action. You can use the MsgBox function instead of "WScript.Echo".

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
Luc Michel
Posts: 14
Joined: Tue Nov 22, 2005 5:06 pm

Good morning/afternoon,

I need to do a custom action, but I don't know the script programming language. Can you look again at my question and reply to me by correcting the lines that are not correct in my script.

Thanks

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

Hi Luc,

The modified script file (according to the instructions in my previous post) is:

Code: Select all

' EditPreferences.vbs
' Sample VBScript to write to a file.
' Author Guy Thomas http://computerperformance.co.uk/
' Ezine 79 Version 2.4 - July 2005
' -------------------------------------------------------------'

Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "c:\Ezine"
strFile = "\GuySays.txt"
strText = "Edit your Ezine Preferences"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
  Set objFolder = objFSO.GetFolder(strDirectory)
Else
  Set objFolder = objFSO.CreateFolder(strDirectory)
  MsgBox "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) Then
  Set objFolder = objFSO.GetFolder(strDirectory)
Else
  Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
  MsgBox "Just created " & strDirectory & strFile
End If

set objFile = nothing
set objFolder = Nothing

' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

' Key Section to write the strText to the file.
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close

' Guy's idea for testing your script.
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
  objShell.run ("Explorer" &" " & strDirectory & "\" )
Else 
  MsgBox "VBScript Error: " & err.number
End If

' End of VBScript to write to a file
Do the following:

1. Create a new text file with the ".vbs" extension and copy the above code.

2. In the Custom Actions page, add a "New Attached" Custom Action and select the file you have created in step 1.

3. Set the following for this Custom Action:
- Function Name: (Leave it empty)
- Execution Options: "Deferred with no impersonation"
- Execution Condition: (Not Installed)

Hope this helps.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
Luc Michel
Posts: 14
Joined: Tue Nov 22, 2005 5:06 pm

Thank you,

It is working without error. But I did that sometimes ago and I feel I need to start from the beginning asking you a couple of questions :

I need a VBS script that will append some text to two existing text files name acad.pat and acadiso.pat on computer systems installed with AutoCAD any version. I have experice with your program and I did something nice last year where the install detect the AutoCAD support folder by searching in the registry. This year, the new install could find the files and append the text to it without asking a single question to the user. Or it can show the folder and offer the choice of changing folder. Useful in some case where many versions of AutoCAD would be installed on the same computer.

It would be great that if the user uninstall, that the files be restored like originally.

Can you guide me to do that ?

Thanks in advance,

Luc
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,
I need a VBS script that will append some text to two existing text files name acad.pat and acadiso.pat on computer systems installed with AutoCAD any version
In order to detect the files on the target machine you can use searches (like you previously did).

Creating the VBScript that modifies the file is an easy task. You can use the
OpenTextFile Method
For more details please. You will also find there a sample script.
http://msdn2.microsoft.com/en-us/library/314cz14s.aspx
Or it can show the folder and offer the choice of changing folder. Useful in some case where many versions of AutoCAD would be installed on the same computer.
In order to achieve this you could create a custom dialog. The dialog is similar to Advanced Installer's FolderDlg.

After the user had selected the folder all you can use a custom action that appends the file names to the folder path and then use the same scrip to modify them.
It would be great that if the user uninstall, that the files be restored like originally.
In order to achieve this, before modifying the files you should back them up to a temporary location. Upon uninstall you can revert them from that temporary location.

Advanced Installer comes with some sample backup/restore script along with a sample project on how to use them.

http://www.advancedinstaller.com/user-g ... le-ca.html

Please let us know if you encounter any problems.

Regards,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
Luc Michel
Posts: 14
Joined: Tue Nov 22, 2005 5:06 pm

Other question

Hello,

I must admit that I cannot do this vb script and choose the necessary setup in Advance Installer. I have read all the help, but I am not a programmer at all. But if you reply with a vb script that works. I need this install to append some text to two existing files. The folder where the files will be detected should be displayed so the user can change it.

Thank you in advance for your support replying with more step by step action to do.

Luc
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,

Please contact me to support at advancedinstaller dot com and I shall provide a sample script and project.

Best regards,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
Rawand
Posts: 13
Joined: Tue Apr 08, 2008 2:33 pm

Re: Script could not be run

Hi, i changed this example to get the portnumber that entered by user during installation and save it to a txt file, but only i could find empty text file created after installation, here is the code summary hope i can get some help, thanks

portNumber= Session.Property("portnumber")
objTextFile.WriteLine(portNumber)

if portnumber is normal string then it will write it in the text file, im confused about whether the problem is in the session or writing to the file
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Script could not be run

Hi,

This happens because you are using a private property ("portnumber"). Note that the value of a private property cannot be passed from the InstallUI sequence (the user interface) to the InstallExecute sequence (when the actual installation is performed).

Please use a public property (its name contains only uppercase letters) and let me know if the problem persists.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Rawand
Posts: 13
Joined: Tue Apr 08, 2008 2:33 pm

Re: Script could not be run

Thanks Cosmin for answering but still not working, here i write toyou all the vbscript which i copied from the one above and all i get as result is a text file containing "Edit your Ezine Preferences" . Thanks


Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText, portNumber, pathToFolder

strDirectory = "C:\Program Files\PC08-test"
strFile = "\GuySays.txt"
strText = "Edit your Ezine Preferences"

Set objFSO = CreateObject("Scripting.FileSystemObject")

portNumber = Session.Property("PORTN")
pathToFolder = Session.Property("APPDIR")

If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If

set objFile = nothing
set objFolder = Nothing

' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
'Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)

' Key Section to write the strText to the file.
' Writes strText every time you run this VBScript


objTextFile.WriteLine(portNumber)
objTextFile.WriteLine(strText)
objTextFile.WriteLine(pathToFolder)
objTextFile.Close
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Script could not be run

Hi,

Is the custom action set as Deferred? Note that deferred custom actions don't have access to installer properties, therefore it should be scheduled as Immediate.
Also, I noticed that the code which sets the value of ForAppending is commented (it will not run). Please make sure that ForAppending is set to 8.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Rawand
Posts: 13
Joined: Tue Apr 08, 2008 2:33 pm

Re: Script could not be run

yes it was Deferred and Immediate solves the problem but how we can have a Custem Action runs at the very end before finalization, even after services installed, because Immediate makes it runs at the begining of the installation. Thanks
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Script could not be run

Hi,

In order to run the custom action at the end of the installation you can schedule it under the "InstallExecuteSequence" -> "InstallFinalize" standard action. You can show a standard action by using the "Show Standard Action " button on the toolbar of the Custom Actions page.

Note that on InstallFinalize a custom action can be scheduled only as Immediate (it is the last step of the installation).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”