views:

630

answers:

2

Writing a script for a custom msi installer action. When my script is invoked by an Installer you can get Installer properties via Session.Property("PropName")

If you don't invoke via installer you get a runtime exception. I want to make my script so I can develop and debug w/o the Installer so how do I catch this error?

I want to do something like:

if Session != null 
  setting=Session.Property("prop1")
else 
  setting="SomeOtherSetting"
end if
+1  A: 

Are you looking for the VBScript syntax to check for null?

How about this:

If (IsNull(Session)) Then
  setting=Session.Property("prop1")
Else 
  setting="SomeOtherSetting"
End If
Jay Riggs
Didn't work :/ I want to just avoid getting a runtime error. The Session object is automatically initialized somehow during by the installer which invokes my script. I want to guard against this runtime object by initializing variables i need some other way while i'm debugging.
blak3r
A: 

The problem is that the Session object isn't defined outside of MSI scripts, so any reference to its properties or methods will raise an exception. To check if an object or a variable is defined, you can use the IsEmpty function:

If Not IsEmpty(Session) Then
  setting = Session.Property("prop1")
Else
  setting = "SomeOtherSetting"
End If

Another possible solution is using the On Error Resume Next statement to catch exceptions caused by referencing the properties and methods of the Session object:

On Error Resume Next

setting = Session.Property("prop1")

If Err.Number <> 0 Then
  setting = "SomeOtherSetting"
End If
Helen
I still get a runtime error with that code.
blak3r