WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Walls on February 07, 2019, 10:07:42 AM

Title: Array value
Post by: Walls on February 07, 2019, 10:07:42 AM
Hello all,

I have set up an IIS website and I am testing the script below. The goal is to collect some basic website information from IIS. Everything seems to work except for pulling the "site binding" information. I think the "site binding" value is in an array, but I am having a hard time extracting it out. Can someone tweak this to show me what I am doing wrong?

strComputer = "."
strClass = "Site"
objService = GetObject(StrCat("winmgmts:\\" , strComputer , "\root\webadministration" ))
objSites = objService.ExecQuery("SELECT * FROM Site")
title = StrCat( strClass , " Class Methods" )

ForEach objSite In objSites
    SiteName = objSite.Name
    SiteId = objSite.Id
    ArrSiteBindings = objSite.Bindings
    ArrDimsElements = ArrInfo ( ArrSiteBindings , 1 )
    For ElementIndex = 0 to ArrDimsElements
      If ElementIndex == ArrDimsElements then break
      SelectedBinding = ArrSiteBindings[ElementIndex]
      Message(ElementIndex ,SelectedBinding)
    Next
Next

Exit
Title: Re: Array value
Post by: JTaylor on February 07, 2019, 10:21:41 AM
No expert but is that an array of Objects?  Do you need something like the following?


hostname = SelectedBinding.Hostname
ip              = SelectedBinding.IP
port          = SelectedBinding.Port

Jim
Title: Re: Array value
Post by: Walls on February 07, 2019, 10:49:30 AM
Yes! Pretty much what is in the attached screen shot. So I guess I am wrong about the array? :-X
Title: Re: Array value
Post by: JTaylor on February 07, 2019, 12:36:27 PM
Not necessarily.  If what you did worked apart from not getting the specific fields and you see a response on

Message(ElementIndex ,SelectedBinding)

then it is an array but the value in the array cell is an object so you need the

hostname = SelectedBinding.Hostname
ip              = SelectedBinding.IP
port          = SelectedBinding.Port

to retrieve the parts.

Again, no expert and I get errors on your script before the Array portion even comes into play so can't test that part easily.

Just trying to help until someone who knows what they are doing replies  ;)

Jim
Title: Re: Array value
Post by: Walls on February 07, 2019, 12:46:55 PM
Thanks, I need all the help I can get. Let me play with it and I will repost.
Title: Re: Array value
Post by: td on February 07, 2019, 01:06:10 PM
WinBatch offers several simple ways to determine the type of a COM Automation supplied variable.  For example, you can simply run the script in the WinBatch Studio debugger.  The Watch window at the bottom of the WBS main frame will contain the variable names and their data types or you can call the ObjectTypeGet function with a variable as the parameter to obtain its data type.   
Title: Re: Array value
Post by: Walls on February 07, 2019, 02:20:25 PM
Thanks for your help.

It tells me the type is string and the value is an ARRAY|VARIANT. Which what I suspected, but I am still struggling to extact the data. I will post back later. 
Title: Re: Array value
Post by: Walls on February 08, 2019, 07:41:55 AM
My post subject is probably not the best for my question, but at the time I didn't know what my issue was. Below is the code I got to work in my environment.  Thanks to all for the comments and help...

Code (winbatch) Select

objService = GetObject(StrCat("winmgmts:\\.\root\webadministration" ))
objSites = objService.ExecQuery("SELECT * FROM Site")


ForEach objSite In objSites
    WebSiteName = objSite.Name
    WebSiteId = objSite.Id
    ArrWebSiteBindings = objSite.Bindings
    type = ObjectTypeGet(ArrWebSiteBindings)
    If type !="EMPTY"
        WebSiteBindingsCnt = ArrInfo (ArrWebSiteBindings, 1)
        ForEach WebSiteBinding In ArrWebSiteBindings
                WebSiteProtocol = WebSiteBinding.Protocol
                WebSiteBindingInfo = WebSiteBinding.BindingInformation
                Display(1,StrCat("Site: ",WebSiteName),StrCat("Site ID: ",WebSiteId," Protocol: ",WebSiteProtocol, " Binding Information: ",WebSiteBindingInfo))

        Next
    End If
Next

Exit