Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Passing parameters to VBScript function


8 replies to this topic

22hn

22hn
  • Members
  • 1 posts

Posted 07 March 2002 - 16:11

When adding a vbscript as a custom action in Wise For Windows Installer 4, there's a field called 'Script Function Call:'.

Anybody who can tell me the syntax for this?

In the vbscript I've defined a function:
Public Function Test1(Param1 as string)

What's the syntax for calling this function and passing the parameter?

Hakan Naslund

Scott Williams

Scott Williams
  • Members
  • 38 posts

Posted 07 March 2002 - 22:22

I can't comment on WfWI, however when you are just working in the raw .MSI files, you can't pass a parameter to a VBScript function directly.  You author the VBScript file as a function, "Sub SomeVBScriptFucntion ... End Sub"  However, a vbscript call has a Session object available to it by default, and you can then read properties that can be set before you make this function call.

For example:

sTmp = Session.Property("SOMEPROPERTY")

This is much like C DLL CA's only have the hInstance argument to their functions (handle to the installer session).

I hope this helps.

skippy31152

skippy31152
  • Members
  • 6 posts

Posted 13 March 2002 - 22:21

Okay, I have the VBScript using the functions and Session.Property(ProductName)

Catch is, when the custom action attempts to execute, it fails with an internal error 2740.  I noticed that since the session may not be accessible during deferred actions, it would be necessary to make this immediate execution.

I did so, and still get the error.  Any ideas as to why this is?  Is there a particular action I have to drop this CA after to access the session properties?

Matt Nowell

Scott Williams

Scott Williams
  • Members
  • 38 posts

Posted 13 March 2002 - 23:32

from the MSI SDK(Nov 2001) help file(msi.chm) , if you didn't know about it, it has listings for all of those error messages.  Very helpful.

2740 Custom action [2] script error [3], [4]: [5] Line [6], Column [7], [8]  Available in Windows Installer versions 1.0, 1.1, and 1.2.

This error isn't typically in your Error table by default, you can add that in, with all the [n] numbers and you will more than likely get a somewhat meaningful error message when your install runs.

It might not even be the Session.Property call that is giving you the error.

skippy31152

skippy31152
  • Members
  • 6 posts

Posted 14 March 2002 - 17:45

Rightio.  That helped out immensely, as now I can actually tell what line/column the script error is happening in.

I'm still having problems with the VBS though, as the MSI file doesn't seem to like any of the Windows Scripthost functions.  I've pasted the code below (along with where the error starts for the moment.  The problem I have is that despite hunting through the SDK for this, I can't find any way to access Network or Session properties in the VBS section:  They seem to be limited to WSH only.

Anybody have any ideas on how to access Session.Property and/or WSH functions in this CA?

Thanks,

Matt Nowell



'Set all variables, constants and functions
Dim fso, folder, file,packagename,productversion,tf, DateInstalled,prodname,prodversion

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso=CreateObject("Scripting.FileSystemObject")
Set tf = fso.OpenTextFile("c:testlog.txt", ForAppending, True)
ERROR HERE Set WshNetwork = Wscript.CreateObject("WScript.Network")
Set WshShell=Wscript.CreateObject("WScript.Shell")
DateInstalled=Now
prodname=Session.Property(ProductName)
prodversion=Session.Property(ProductVersion)

'Now, write the information to the file in the format Packagename,ProductVersion,Username,Computername,1,DateInstalled
tf.write prodname & ","
tf.write prodversion & ","
tf.write wshnetwork.username & ","
tf.write wshnetwork.computername & ","
tf.write DateInstalled & ","


tf.Writeline "1"
tf.Close

Scott Williams

Scott Williams
  • Members
  • 38 posts

Posted 14 March 2002 - 20:06

Well, right away, you need those to be

prodname=Session.Property("ProductName")
prodversion=Session.Property("ProductVersion")

Need the quotes!

Not sure why you can't create the Network object.  I think the WScript object is there by default, and you probably don't need to do a CreateObject on it, just use WScript.Network.

DavidCahill

DavidCahill
  • Members
  • 19 posts

Posted 21 March 2002 - 13:41

try just using CreateObject instead of WScript.CreateObject
David

Scott Williams

Scott Williams
  • Members
  • 38 posts

Posted 21 March 2002 - 15:15

Yes, I have recently discovered (might have been here or on the MS news groups) that the WScript object is not available to VBS functions called as CA's.  CreateObject will work, not sure what to tell you about the WScript.Network object, that may or may not be available with the CreateObject Call.

skippy31152

skippy31152
  • Members
  • 6 posts

Posted 21 March 2002 - 15:40

Actually, I managed to get the code working entirely when set up as a type 6 CA (executed from binary table).  Code is pasted below for your use.

I'm working at the moment on getting it to write directly to a DB table for a great way to log installs and potentially create an automated licensing setup.  

Matt



'Set all variables, constants and functions
Dim fso, folder, file,packagename,productversion,tf, DateInstalled,prodname,prodversion

Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Set fso=CreateObject("Scripting.FileSystemObject")
  Set tf = fso.OpenTextFile("c:\testlog.txt", ForAppending, True)
  Set WshNetwork=CreateObject("WScript.Network")

  DateInstalled=Now
  prodname=Session.Property("ProductName")
  prodversion=Session.Property("ProductVersion")

'Now, write the information to the file in the format Packagename,ProductVersion,Username,Computername,1,DateInstalled  
  tf.write prodname & ","
  tf.write prodversion & ","
 tf.write wshnetwork.username & ","
 tf.write wshnetwork.computername & ","
  tf.write DateInstalled & ","
 

  tf.Writeline "1"
  tf.Close