Server Management Suite

 View Only
  • 1.  vbscript custom inventory fail on non existant regkey

    Posted Jun 19, 2012 08:42 PM

    VBscript noob here (this is the result of a lot of work by someone else) - I found that running this script w/o the altiris pieces, writing to the db, that it hums along just fine without issue.  However, as soon as I add in all the altiris code and the add new row information, that it suddenly reaches a fail point.

    If this script finds a pathe/regkey that does not exist, let's say TCPPort for example, it fails out and does not collect any other information below that point.  I'm left with

        objDataRow.SetField 5, TCPPort   
        objDataRow.SetField 6, sClusterName
        objDataRow.SetField 7, CurrentVersion  
        objDataRow.SetField 8, sCluster

    all set to NULL.  I've run into this issue in the past and to skate by the issue, I have it check the regkey before hand with an if/then and so if there is no key, we set it to "", which is NOT what I'd like to do going forward.  In our 6.5 database, the xml equivalent would drop the information and it would have an empty space.  Is there an easy way to get this same functionality through 7.1 or am I doomed to have if/then statements for every row going forward?

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

    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Dim strKeyPath1

    On Error Resume Next


    ''' Altiris Stuff
    'Create instance of Altiris NSE component
    dim nse
    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

    ' Set the header data of the NSE
    ' Please don't modify this GUID
    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
    nse.Priority = 1

    'Create Inventory data block. The following data class with below guid is already configured on server.
    'Brackets are required around the dataclass guid.
    dim objDCInstance
    set objDCInstance = nse.AddDataClass ("{4452fdff-3511-4998-b4c8-9c581b9256d9}")

    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
    ''' End of Altiris Stuff

    'Call the method for the first key we are looking for
    FindKeyValue("Software\Microsoft\Microsoft SQL Server")
    'Need to call it twice



    '-------------------------------------------------------------------------
    Function FindKeyValue(strKeyPath)
        
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
            strComputer & "\root\default:StdRegProv")

        errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)
        
        If (errorCheck=0 and IsArray(arrSubKeys)) then
            For Each subkey In arrSubKeys
                Wscript.Echo subkey

                oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\" & "setup","PatchLevel",strValue
            
            If IsNull(strValue) Then
                    Wscript.Echo "The registry key does not exist."
            Else
                    Wscript.Echo "The registry key exists."
                    
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\setup","edition",Edition
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\setup","patchlevel",PatchLevel
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\setup","SqlPath",SqlPath
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\setup","SQLDataRoot",SQLDataRoot
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\MSSQLServer\SuperSocketNetLib\Tcp","TcpPort",TCPPort
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\MSSQLServer\CurrentVersion","CurrentVersion",CurrentVersion  
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\Cluster","ClusterName",sClusterName
         If IsNull (sClusterName) Then
                         sCluster = "False"
         Else     sCluster = "True"
                    
            End If        
            
                        'Add a new row
        dim objDataRow
        set objDataRow = objDataClass.AddRow
        'Set columns
        objDataRow.SetField 0, subkey
        objDataRow.SetField 1, Edition  
        objDataRow.SetField 2, PatchLevel
        objDataRow.SetField 3, SqlPath
        objDataRow.SetField 4, SQLDataRoot
        objDataRow.SetField 5, TCPPort   
        objDataRow.SetField 6, sClusterName
        objDataRow.SetField 7, CurrentVersion  
        objDataRow.SetField 8, sCluster
                     
                    Wscript.echo "Key:" & subkey
                  Wscript.echo "Edition:" & Edition
                Wscript.echo "Patch Level:" & PatchLevel
                Wscript.echo "TCPPort:" & TCPPort
                Wscript.echo "Sql Path:" & SqlPath
                Wscript.echo "SQLData Root:" & SQLDataRoot
                Wscript.echo "Cluster Name:" & sClusterName
                Wscript.echo "Current Version:" & CurrentVersion
                Wscript.echo "Cluster:" & sCluster
                        
                        
                        'Need to push all the data in to the NSI
            End If


            Next
        End If

    end Function


    '-------------------------------------------------------------------------               
                   

        
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
            strComputer & "\root\default:StdRegProv")


    strKeyPath1 = "Software\Microsoft\MSSQLServer"
                oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "setup","PatchLevel",strValue
        
            If IsNull(strValue) Then
                    Wscript.Echo "The registry key does not exist."
            Else
                    Wscript.Echo "The registry key exists."
     
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\setup","edition",Edition
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\setup","patchlevel",PatchLevel
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\setup","SqlPath",SqlPath
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\setup","SQLDataRoot",SQLDataRoot
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\MSSQLServer\SuperSocketNetLib\Tcp","TcpPort",TCPPort
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\MSSQLServer\CurrentVersion","CurrentVersion",CurrentVersion                
                    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath1 & "\" & "\Cluster","ClusterName",sClusterName
         If IsNull (sClusterName) Then
                         sCluster = "False"
         Else     sCluster = "True"
                    
            End If    
            
                       
                        'Add a new row
        dim objDataRow
        set objDataRow = objDataClass.AddRow
        'Set columns
        objDataRow.SetField 0, "Default"
        objDataRow.SetField 1, Edition  
        objDataRow.SetField 2, PatchLevel
        objDataRow.SetField 3, SqlPath
        objDataRow.SetField 4, SQLDataRoot
        objDataRow.SetField 5, TCPPort   
        objDataRow.SetField 6, sClusterName
        objDataRow.SetField 7, CurrentVersion  
        objDataRow.SetField 8, sCluster
                           
                    Wscript.echo "Key:" & "Default"
                  Wscript.echo "Edition:" & Edition
                Wscript.echo "Patch Level:" & PatchLevel
                Wscript.echo "TCPPort:" & TCPPort
                Wscript.echo "Sql Path:" & SqlPath
                Wscript.echo "SQLData Root:" & SQLDataRoot
                Wscript.echo "Cluster Name:" & sClusterName
                Wscript.echo "Current Version:" & CurrentVersion
                Wscript.echo "Cluster:" & sCluster
                        
                        
                        'Need to push all the data in to the NSI
            End If
       


    ''' Altiris Stuff
    ' Send the NSE data to the NS server
    nse.SendQueued
    ''' End of Altiris Stuff
    ''' End of vbscript main logic



  • 2.  RE: vbscript custom inventory fail on non existant regkey

    Posted Jun 20, 2012 01:36 PM
      |   view attached

    I kinda rewrote it.  The logic should be a bit simpler now.  I'm assuming here that you're only looking for data on the SQL engine itself and not AS or RS.  And I couldn't think of a simpler way to check for null values.  You could actually query the registry before doing the GetString, but that's actually MORE code than the IF THEN stuff.

    Let me know if it works.

    Attachment(s)

    txt
    CI-MSSQL.txt   3 KB 1 version