WMI and Host Integration Server…

Internally and externally we get customer inquiries wanting to know how to get configuration and status information from Host Integration Server without using the manager interface.

Well, this is fairly simple, but complicated if you are not familiar with using WMI. Most users are familiar with using snacfg.exe, which is documented fairly well. However, for many things, WMI is your friend.

Now, to be honest, I cheat. When we first added in WMI into the product, I was totally unfamiliar with it. I started playing, using wbemtest (which comes with the operating system), and looking at samples. Then, I discovered WMI Code Creator. This is a great tool for ‘simple’ things, and what I really like is it will create, besides VBScript code, C# and VB.NET code. Using this tool gave me a greater understanding in how to create queries to gather information I needed (in conjunction with using wbemtest).

So, one question that came across our internal alias recently was “I'm wondering if SNACFG.EXE is able to display all LUs assigned for each pool.” Well, yes, but not cleanly, and what if you needed a bit more information, like is the LU actually being used, etc?

Here is where WMI comes in handy.

Using WMI, the below query will display every LU in a pool:

    1: OPTION EXPLICIT
    2: Dim strDomainComputer, strPoolTargeted
    3: Dim WmiLocator, WmiNameSpace
    4: Dim objLuInThisPool
    5: Dim xLuInPool
    6: Dim objPool, xPool
    7:  
    8: Set WmiLocator = CreateObject("WbemScripting.SWbemLocator")
    9: strDomainComputer = "."
   10:  
   11: BigLoop()
   12:  
   13: Private Sub DoPool()
   14:        Wscript.Echo "Checking POOL " & xPool.Name
   15:        strPoolTargeted   = xPool.Name
   16:        Set objLuInThisPool = WmiNameSpace.ExecQuery("Select Name from MSSna_LuDisplay where PoolName='" & strPoolTargeted & "'")
   17:        if objLuInThisPool.Count > 0 then
   18:               for each xLuInPool in objLuInThisPool
   19:                      wscript.echo "     " & xLuInPool.Name
   20:               next
   21:        end if
   22:        Wscript.Echo "Total LU count for the pool " & strPoolTargeted & " is " & objLuInThisPool.Count
   23:        Wscript.Echo “”
   24: End Sub
   25:  
   26: Private Sub BigLoop()
   27:        Set WmiNameSpace = WmiLocator.ConnectServer(strDomainComputer,"root\MicrosoftHIS")
   28:        Set objPool = WmiNameSpace.ExecQuery("Select Name from MsSna_PoolDisplay")
   29:        For Each xPool In objPool
   30:               DoPool()
   31:        next
   32: End Sub

What this code does is 1st makes a query to get each pool defined on the machine, then makes a query based on the pool name to get the LUs using that pool.

But say you need a bit more? As in wanting to find out what sessions were actually in use?

Well, that can be done fairly easily as follows:

    1: rem - this will dump out all InSession or SSCP 3270 LUs
    2: rem - Also, the script will display as follows
    3: rem - Connection name 
    4: rem - 3270 LU name
    5: rem - Status the LU is in at the time (either SSCP or InSession)
    6: rem - User Account accessing the LU
    8: strComputer = "." 
    9: quote = chr(34)
    7:  
   10: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftHIS") 
   11: Set colItems = objWMIService.ExecQuery( "SELECT * FROM MsSnaStatus_Lu3270 WHERE StatusText = 'SSCP' OR StatusText = 'InSession'",,48) 
   12: Wscript.Echo "---------------------------------------------------------------------------------------------------------"
   13: For Each objItem in colItems
   14:       Messagestr = "ConnectionName: " & objItem.ConnectionName & vbtab 
   15:       Messagestr = Messagestr & "Name: " & objItem.Name & vbtab 
   16:       Messagestr = Messagestr & "StatusText: " & objItem.StatusText & vbtab
   17:     rem map the 'active' 3270 LU to the user account accessing it
   18:     qrystring = "references of {MsSnaStatus_Lu3270.Name=" & quote & objItem.Name & quote & "}"
   19:     set colitems1 = objWMIService.ExecQuery( qrystring,,48) 
   20:       For Each objItem1 in colitems1 
   21:       rem - strip out MsSnaStatus_ClientConnection.Name= from the item....
   22:             Messagestr = Messagestr & "User" & Mid (objItem1.PathToUser,34)
   23:       Next
   24:       Wscript.Echo Messagestr
   25: Wscript.Echo "---------------------------------------------------------------------------------------------------------"
   26: Next
   27: WScript.Echo ""

The output from this script would be similar to this:

    1: ---------------------------------------------------------------------------------------------------------
    2: ConnectionName: D3270   Name: D3270002  StatusText: SSCP        User: W2KS2/ Administrator"
    3: ConnectionName: D3270   Name: D3270003  StatusText: InSession   User: W2KS2/ Bob"
    4: ConnectionName: D3270   Name: D3270004  StatusText: SSCP        User: W2KS2/ Jane"
    5: ConnectionName: D3270   Name: D3270005  StatusText: SSCP        User: W2KS2/ Ted"
    6: ConnectionName: D3270   Name: D3270005  StatusText: InSession   User: W2KS2/ Alice"
    7: ---------------------------------------------------------------------------------------------------------

Please note this last query only queries against the local Host Integration Server. If you have multiple servers, things can be more complicated, as status information has to be queried against each Host Integration Server in the ‘HIS sub domain’.

I hope this is helpful to many of you out there. WMI can be most helpful when gathering information that is not as easily available in the manager interface.