thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

referencing temporary files in vbscript

I am needing to make a reference to some temporary files in vbscript. However, I receive an error indicating the property could not be found.

Here is the command issued in vbscript.

set PSCP.EXE=session.property("PSCP.EXE")

Here is the error.

Microsoft VBScript runtime error: Object required: 'PSCP'

The pscp.exe executable has been added as a temporary file so it should be able to locate it.

Any suggestions?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Here are the problems with the command you are using:
- you are using a variable which contains a dot (".") character; note that in this case what is before the dot is considered an object (in your case "PSCP")
- you are using the set statement; a correct instruction would be this:

Code: Select all

a=Session.Property("PSCP.EXE")
- make sure that this custom action is not set as Deferred in the "Custom Action Properties" page (deferred custom actions don't have access to installer properties)

Let me know if the problem persists after making the necessary modifications.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

Thanks for the reply Cosmin.

1) the "." dot did not seem to make a difference for referencing installed files but it did seem to impact referencing temporary files. I had another file property that was an installed file that worked fine in the same custom action with a "." dot in the reference.

2) I noticed that temporary file properties get prepended with "AI_". So I had to reference the file property as AI_PSCP.EXE.

3) I did have the custom action set as a deferred custom action, which after correcting the file property reference, came back as a blank value. I then changed it to Immediate execution and it then seemed to work. Although now I have the issue that the file path reference cuts off. Here is what I get "C:\Program Files\You". I just setup a simple test project with the default naming so it should be "C:\Program Files\Your Company\Your Application\pscp.exe". It seems to truncate at 20 characters. I have also tried it with a directory that has no spaces such as "C:\tmp\longnamedirectory" and it results with "C:\tmp\longnamedirec". What is even weirder is that if I define a path less that 20 characters it still produces an error.

Here is the error I get:

Microsoft VBScript runtime error: Object required: '[string: "C:\tmp\appdir\"]'

So I am out of ideas. Please help!

As a background, I was previously executing pscp.exe, putty.exe and plink.exe as attached custom actions. However after reading the following post, I wanted to adopt the idea of executing these applications in the background:

http://www.advancedinstaller.com/forums ... and+window

So with that in mind, is there perhaps a better way of achieving my goal?

I don't want pscp.exe, plink.exe and putty.exe to be installed and left on the system after install. I just want them available during the install.

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

Hi,

The problem you are encountering is probably due to the wrong use of quote characters around file/folder paths.

A better and simpler alternative to using a VBScript Custom Action would be the "CreateExeProcess" function exported by the "aicustact.dll".

Supposing that you want to execute the following command (to redirect the output of "pscp.exe", suppressing the console window):

Code: Select all

pscp.exe -pgpfp > "C:\Program Files\out.txt"
you should follow the steps below:

1. Add "pscp.exe" as a Temporary File in the Files and Folders page, under "Windows Volume\Temporary".

2. In the Custom Actions page, add the "CreateExeProcess" CA as described in the following post:
http://www.advancedinstaller.com/forums ... 3991#13991

3. Set the "Action Data" field to the command you want to execute, in this case:

Code: Select all

"[%ComSpec]" /C "[AI_PSCP.EXE]" -pgpfp > "[ProgramFilesFolder]out.txt"
I shall explain the command used:

a) "[%ComSpec]" is a Formatted value which at install time resolves to the value of the "ComSpec" environment variable (which designated the command interpreter). It is enclosed within quotes because its full path may contain spaces.

The command (pscp.exe -pgpfp > out.txt) must be invoked through the command interpreter because I/O redirection (used in the example) is available only within the command shell.

The /C switch executes the specified command (within quotes) and then terminates the "cmd.exe" process.

b) The file path containing the redirected output from "pscp.exe" is enclosed within quotes (because file paths usually contain spaces). The command to be executed by "cmd /C" is not necessary to be enclosed within quotes.

4. Set the Execution Properties of the Custom Action to "Synchronous Execution, ignore return code" because the CreateExeProcess function will return a value based on the exit code of the executed command (in this case "cmd.exe") and that may cause the installation to fail.

5. Set the Execution Options to "Deferred with no impersonation" if the CA performs system changes (as it is the case now, since a file "out.txt" gets created under "Program Files").

You can also select "Immediate execution" if the command you execute does not perform system changes.

6. Set the Execution Condition appropriately, most often it will be:

Code: Select all

(Not Installed)
7. Build and install the package. If you have followed the above steps correctly, a file named "out.txt" should be present under "Program Files", containing the output from the "pscp.exe -pgpfp" command.

If you encounter any problems, please post the exact commands you want to execute and I shall give you more details.

Hope this helps.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

Hi Ionut,

That seemed to work out exactly the way I was needing it.

A couple of things I noticed though.

1) I didn't seem to need the quotes at all. The paths to the executables I referenced were automatically converted to dos format.

2) The %comspec% variable didn't seem to work. It seems that it did not translate the environment variable. I know this environment variable works because I have used it before and is quite commonly used for Windows XP. But the CA method didn't seem to translate the environment variable to the path of the cmd.exe executable.

3) I didn't seem to even need to call cmd.exe, as long as an executable (e.g. pscp.exe) was the first value within the Action Data: field. However, if an executable is not the first value within the Action Data: field (e.g. echo y | pscp.exe) then the command will not work and must require the "cmd.exe /C" as the first value.

I greatly appreciate the help.

Thanks so much!

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

Hi Trey,
1) I didn't seem to need the quotes at all. The paths to the executables I referenced were automatically converted to dos format.
Quotes are not always required but should be used nonetheless for compatibility with Win9x systems and for security reasons. See the "Security Remarks" section for the "CreateProcess" API here:
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
2) The %comspec% variable didn't seem to work. It seems that it did not translate the environment variable. I know this environment variable works because I have used it before and is quite commonly used for Windows XP. But the CA method didn't seem to translate the environment variable to the path of the cmd.exe executable.
Make sure that you use the Formatted value "[%ComSpec]" (note the square brackets and single percent character), not "%comspec%" (as in BAT files).
3) I didn't seem to even need to call cmd.exe, as long as an executable (e.g. pscp.exe) was the first value within the Action Data: field. However, if an executable is not the first value within the Action Data: field (e.g. echo y | pscp.exe) then the command will not work and must require the "cmd.exe /C" as the first value.
The command interpreter ("cmd.exe") is required only when you use I/O redirection or pipes (which are available only within the command shell). Instead of the "echo" command, you could have piped the output of an external console application to "pscp.exe" and the "cmd.exe" interpreter would have still been required.

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

Return to “Common Problems”