Embeded VBscript error
I have added a VB script custom action type 3110 to an MSI. It is giving VBSript runtime error: Object required: 'WScript" on the first line that references wscript.
Set StdIn = WScript.StdIn
I read a reference to not using wscript calls in a vbscript here but I don't know what is the alternative?
Set StdIn = WScript.StdIn
I read a reference to not using wscript calls in a vbscript here but I don't know what is the alternative?
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
The alternative? Use the object without the WScript directive! WScript refers to the Windows Scripting Host script interpreter. The WI engine uses its own interpreter and knows nothing of WSH. This makes testing of scripts external to WI tricky. What I do is set a Boolean according to whether a well-known MSI property is available:
Option Explicit
Dim blnIsCustomAction
blnIsCustomAction = False
blnIsDeferred = False
On Error Resume Next
If IsObject(Session) Then
'// We may have arrived here because error-trapping is off
If Err.Number = 0 Then
blnIsCustomAction = True
End If
End If
'// We test a well-known property and, if it's empty, we MUST be in deferred mode, right?
If Len(Session.Property("UpgradeCode")) = 0 Then
blnIsDeferred = True
End If
On Error Goto 0
Then, later in the code, we can use those Booleans to branch accordingly:
If blnIsCustomAction Then
If blnIsDeferred Then
strTarget = Split(Session.Property("CustomActionData"), ",")(0)
strGroupName = Split(Session.Property("CustomActionData"), ",")(1)
Else
Select Case LCase(strObjectType)
Case "file"
strTarget = Session.Property("FILETOPERMISSION")
Case "folder"
strTarget = Session.Property("FOLDERTOPERMISSION")
Case Else
strTarget = Session.Property("REGKEYTOPERMISSION")
End Select
strGroupName = Session.Property("APPGROUPNAME")
End If
End If
I use it primarily so that my scripts can be run in Execute Immediate of Execute Deferred with minimal editing in between but by testing the Boolean blnIsCustomAction, you can have different sections called depending on whether the script's being run by WSH or by the WI engine.
Posted by:
captain_planet
15 years ago
Posted by:
anonymous_9363
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.