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

Problem with a VBScript custom action


6 replies to this topic

ajshurts

ajshurts
  • Full Members
  • 5 posts

Posted 30 March 2007 - 00:20

If anyone could take a look at the following custom action, I would appreciate the feedback. This custom action is triggered from a DoAction event on a dialog next button. The custom action fails and the install immediately goes to the finish dialog. It's a type 6 custom action. As usual, the code works outside Windows Installer and I am wondering if there are restrictions on using the RegExp object in Windows Installer. Thanks in advance for the help.

CODE
Sub VerifyInfo()
   dim strSerial, strHost, strPattern
   dim objRegExp
   strSerial = Session.Property("SERIAL")
   strHost = Session.Property("HOST")
   Set objRegExp = New RegExp
   strPattern = "[a-fA-F0-9]{8}\-[a-fA-F0-9]{8}"
   objRegExp.Pattern = strPattern
   If(objRegExp.Test(strSerial)) Then
    Session.Property("SERIAL_VALID")=1
   Else
    Session.Property("SERIAL_VALID")=0
   End If
   strPattern = "^(http)s?(\:\/\/)([a-zA-Z0-9\.\-]+)((\/)?)$"
   objRegExp.Pattern = strPattern
   If(objRegExp.Test(strHost)) Then
    Session.Property("URL_VALID")=1
   Else
    Session.Property("URL_VALID")=0
   End If        
End Sub


ajshurts

ajshurts
  • Full Members
  • 5 posts

Posted 30 March 2007 - 16:47

Some extra info...

It is crashing when executing the Test method. It is however able to create the RegExp object and set the Pattern property. I also tried the Execute method, but it crashed as well. If this helps, I am on script version 5.7 and Windows Installer 3.1.

Zweitze

Zweitze
  • Full Members
  • 522 posts

Posted 31 March 2007 - 17:55

The RegExp object was introduced in Active Scripting 5.0, which comes with a number of products, IE 5.0 is one of them.

What you can do is start with "On Error Resume Next", causing the script to continue despite any errors occuring.
To find out more information about the errors that did occur, write after each suspicious statement:

if Err.Number <> 0
MsgBox Err.Description
Err.Clear
endif

Also consider writing "Option Explicit" at the top of the script (before the Sub), this forces the script to generate an error when a variable is introduced that was not DIMmed (usually means a typing error).

Hope this helps you debug your scripts.

Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 02 April 2007 - 04:48

I am not sure, but I think MSI hosts is own VBScript runtime that is run in quiet mode. I am hence not sure if message boxes will show up. If you don't see any boxes, try writing Err.Description to a log file instead. Again, not positive if message boxes are suppressed, but just in case...
Regards
-Stein Åsmul

akerl

akerl
  • Full Members
  • 104 posts

Posted 02 April 2007 - 12:03

The solution is simple. Session.Property need a string but you set a integer value. The following code works perfectly:

Sub VerifyInfo()
dim strSerial, strHost, strPattern
dim objRegExp
strSerial = Session.Property("SERIAL")
strHost = Session.Property("HOST")
Set objRegExp = New RegExp
strPattern = "[a-fA-F0-9]{8}\-[a-fA-F0-9]{8}"
objRegExp.Pattern = strPattern
If(objRegExp.Test(strSerial)) Then
Session.Property("SERIAL_VALID")="1"
Else
Session.Property("SERIAL_VALID")="0"
End If
strPattern = "^(http)s?(\:\/\/)([a-zA-Z0-9\.\-]+)((\/)?)$"
objRegExp.Pattern = strPattern
If(objRegExp.Test(strHost)) Then
Session.Property("URL_VALID")="1"
Else
Session.Property("URL_VALID")="0"
End If
End Sub

Additionally: Your CA is unsecure, because the script logic is readable by everyone. It is better to use DLL for such implementation.


Andreas Kerl

Inside Windows Installer 4.5
ISBN 3-86645-431-7


Glytzhkof

Glytzhkof
  • Moderators
  • 1,447 posts

Posted 03 April 2007 - 03:10

I agree on the security issue, however it would probably be even better to do the serial code validation in the application.
Regards
-Stein Åsmul

ajshurts

ajshurts
  • Full Members
  • 5 posts

Posted 09 April 2007 - 21:28

QUOTE (akerl @ 2007-04-02 12:03)
The solution is simple. Session.Property need a string but you set a integer value. The following code works perfectly:

Sub VerifyInfo()
dim strSerial, strHost, strPattern
dim objRegExp
strSerial = Session.Property("SERIAL")
strHost = Session.Property("HOST")
Set objRegExp = New RegExp
strPattern = "[a-fA-F0-9]{8}\-[a-fA-F0-9]{8}"
objRegExp.Pattern = strPattern
If(objRegExp.Test(strSerial)) Then
Session.Property("SERIAL_VALID")="1"
Else
Session.Property("SERIAL_VALID")="0"
End If
strPattern = "^(http)s?(\:\/\/)([a-zA-Z0-9\.\-]+)((\/)?)$"
objRegExp.Pattern = strPattern
If(objRegExp.Test(strHost)) Then
Session.Property("URL_VALID")="1"
Else
Session.Property("URL_VALID")="0"
End If
End Sub

Additionally: Your CA is unsecure, because the script logic is readable by everyone. It is better to use DLL for such implementation.

Thank you!! I can't believe I overlooked that. This isn't the actual serial number validation. We have a DLL that does that in the application. However, I want to make sure what they enter is in a valid format. Thanks a ton for the help.