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

Error in Executing VB script as CA


4 replies to this topic

jagat

jagat
  • Members
  • 15 posts

Posted 07 June 2002 - 10:44

Hi,
I am using Installsheild Developer 7.01 Basic Msi Project.
I want to list all the default websites on a server dynamically in a combobox.Therefore I tried to get the website names through Getobject method and display them for Testing purpose.
But the VB Script was failing to instantiate the default websites though the same script would work perfectly in VB project.
Here is the code that I am executing through the Custom action...
Type : Run VBScript code
Location : directly Stored directly in the custom action
In Script Execution : Immediate
'I amtrying here to get the list of websites as a string to display in a Message Box.
But the script fails just after the for loop showing
"Variable is undefined"
--------------------------------------------------------------------------------

Option Explicit
Dim IISOBJ,IISWebSite,IISWebSiteRoot
Dim Entry
Dim Result
On Error Resume Next
Set IISOBJ = GetObject("IIS://LocalHost/W3SVC")
 If (Err.Number <> 0) Then
       MsgBox "Server doesnt exists"
 End If
For Each Web In IISOBJ
 If (Web.Class = "IIsWebServer") Then
   Set IISWebSite = GetObject("IIS://localhost/W3SVC/" & Web.Name)
   Set IISWebSiteRoot = GetObject("IIS://localhost/W3SVC/" & Web.Name & "/ROOT")
     If (Err.Number <> 0) Then
        MsgBox Err.Description
     End If
   Result = IISWebSite.Servercomment & Space(40 - Len(IISWebSite.Servercomment))
   Entry = UCase("w3svc") & " " & Web.Name & "  " & Result
   Set IISWebSiteRoot = Nothing
   Set IISWebSite = Nothing
 End If
Next
MsgBox Entry
Set IISOBJ = Nothing
--------------------------------------------------------------------------------
Can anyone help me out in solving the above problem.
Thanks in advance.
Regards,
jagat
jagat
Software Engineer
http://www.icode.com

Stefan Secker

Stefan Secker
  • Members
  • 46 posts

Posted 10 June 2002 - 14:09

Hi jagat,

you have to dim the variable you called "Web",
then it will work!  :D

Cheers
          Stefan

jagat

jagat
  • Members
  • 15 posts

Posted 11 June 2002 - 11:01

Hi Stefan,
  Thankyou verymuch for the information..   :D

Now the major problem am facing is in populating the combobox.I tried to call the custom action by storing the VB Script directly but the setup would terminate showing the runtime error 1720 (There is a problem with the Windows Installer package. A script reqd for the install to complete cudnt be run).
Therefore I changed the CA to run the VbScript stored in the binary table.
And the Script is geting executed without showing any error but its not populating the combobox..I may be missing something great ..
Here is the .vbs script

------------------------------------------------------------
   
   

public function FirstFunc()
'Option Explicit
 Dim IISOBJ,IISWebSite,IISWebSiteRoot
 Dim Web
 Dim Entry
 Dim Result
 Dim oDatabase
 Dim oView
 Dim oInstaller

 Dim oRecord
 Dim intCount
 Dim oRecordEr


 On Error Resume Next
   Set IISOBJ = GetObject("IIS://LocalHost/W3SVC")
     If (Err.Number <> 0) Then
        MsgBox "Server doesnt exists"
       'wscript.Quit
     End If
'---------------------------------------------
   On Error Resume Next

   Set oDatabase = Session.Database

   Set oView = oDatabase.OpenView("SELECT * FROM ComboBox WHERE  Property='WWWSERVERINSTANCE'")
   If oView Is Nothing Then
     Set oDatabase = Nothing
     Exit Function
   End If

    Set oInstaller = Session.Installer
'----------------------------------------------------



   For Each Web In IISOBJ
       If (Web.Class = "IIsWebServer") Then
       Set IISWebSite =
GetObject("IIS://localhost/W3SVC/" & Web.Name)
       Set IISWebSiteRoot =
GetObject("IIS://localhost/W3SVC/" & Web.Name &
"/ROOT")
            If (Err.Number <> 0) Then
               MsgBox Err.Description
              'wscript.Quit
            End If
      Result = IISWebSite.Servercomment & Space(40 -
Len(IISWebSite.Servercomment))
       Entry = UCase("w3svc") & " " & Web.Name & "  " &
Result
      Set oRecord = oInstaller.CreateRecord(4)
      If Not oRecord Is Nothing Then
         'Set the property of the control to which the
records are to be attached
          oRecord.StringData(1) = "WWWSERVERINSTANCE"
          oRecord.IntegerData(2) = Web.Name '(integer)
          oRecord.StringData(3) = Result
          oRecord.StringData(4) = Result
        End If

      On Error Resume Next
      'Read/Write on to the view
      oView.Modify 7,oRecord

       Set oRecord = Nothing

       Set oRecordErr = oInstaller.LastErrorRecord
       If Not oRecordErr Is Nothing Then
          For intCount = 0 to oRecordErr.FieldCount
              ShowError oRecordErr.StringData & " " &  
         oRecordErr.IntegerData
             Set oRecordErr = Nothing
             Exit Function
          Next
        End If

     Set IISWebSiteRoot = Nothing
     Set IISWebSite = Nothing
   End If
 Next
 oView.Close
 Set oView = Nothing
 Set oDatabase = Nothing
 Set oInstaller = Nothing
 Set oRecord = Nothing
 Set oRecordErr = Nothing
 Set IISOBJ = Nothing
End Function


Can anyone help me out again..
Thanks and Regards.
jagat
jagat
Software Engineer
http://www.icode.com

Stefan Secker

Stefan Secker
  • Members
  • 46 posts

Posted 11 June 2002 - 17:27

Hi jagat,

I played around with that issue for some time and
found several strange things there.

All my tries broke at the Modify method, but i
didn't look any deeper into the correct syntax. Seems
that you have to call some other functions before
that, when you use a "SELECT" view. ???

Anyhow, you should check/install the MS Windows
Installer SDK and look for file called WiRunSQL.vbs.
This one can be called with parameters to add records
to any table of an MSI, so i guess the code in there
will help you to accomplish what you want to do.

HTH
   Stefan

jagat

jagat
  • Members
  • 15 posts

Posted 14 June 2002 - 08:53

Hi Stefan,
Thanks again .. :)
I cought the mistake , I was trying to assign Web.Name
as an Integer..
oRecord.StringData(1) = "WWWSERVERINSTANCE"
         oRecord.IntegerData(2) = Web.Name '(integer) //This was the problem.
         oRecord.StringData(3) = Result
         oRecord.StringData(4) = Result
Anyway its now working fine..
Regards,
jagat
jagat
Software Engineer
http://www.icode.com