Client Management Suite

 View Only
Expand all | Collapse all

Anyone have an example of a custom inv script to pull a registry hive?

  • 1.  Anyone have an example of a custom inv script to pull a registry hive?

    Posted Dec 05, 2012 11:39 AM

    I am looking for a script that will pull a registry hive

    example

    HKLM\Software\MyKey

    Where it has multiple value's and each value has some data

    I want it to pull everythign in the hive into a custom data clasee

    so that I will end up with my data class showing 2 colums and rows

     

    so basically from looking at a reg export this is what I have and would want in the database where mykey is the class

    [HKEY_LOCAL_MACHINE\SOFTWARE\MyKey]
    "ImageCutDate"="5/11/11"
    "ImageVersion"="Windows 7 Pro SP1"
    "Win7Revision"="2"
    "Win7"="1"
    "SP1"="True"
    "Brand"="Lenovo"
    "Model"="T420s"
    "Type"="Laptop"

     

    I see examples of pulling just 1 registry key or targetted, but the values in this reg key vary and could be 10 per machine or 100 per machine.

     



  • 2.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Dec 06, 2012 07:45 PM


  • 3.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Dec 07, 2012 09:56 AM

    It looks like that script is getting specific values that they know about, unless I'm just reading the script wrong, which I could be I'm not a VB guru. I want to pull every single value in the registry key , some may not be known as they may be added manually or by processes that don't exist now but will in the future

     

    EX:

    today the key may contain only these values

    myvalue1=25

    myvalue2=test

     

    and then tomorrow maybe it no longer has myvalue1 but rather has myvalue3,  So I need a script that will just recursivly get every single value and its data in a registry hive.

     



  • 4.  RE: Anyone have an example of a custom inv script to pull a registry hive?
    Best Answer

    Posted Dec 07, 2012 04:58 PM

    Ok doing some searching and modifying some scripts and adding in the altiris specific NSE creation I did get a script to work.  I know my values are only REG_SZ or REG_DWORD, so I ignore anything else found in the hive. 

    I still have to add error handling in case the registry hive doesn't exist but this script does what I need and populates a dataclass for the pc with multiple rows for each value/data combo in the registry hive.

     

     

    'Custom Inventory Script to grab a registry hive and inventory all String and DWord
     
    const HKEY_LOCAL_MACHINE = &H80000002
    const REG_SZ = 1
    const REG_EXPAND_SZ = 2
    const REG_BINARY = 3
    const REG_DWORD = 4
    const REG_MULTI_SZ = 7
     
     
    'Create instance of Altiris NSE component
    dim nse
    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")
     
    ' Set the header data of the NSE
    ' Please dont modify this GUID
    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
    nse.Priority = 1
     
    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server
    dim objDCInstance
    'User your custom data class GUID here
    set objDCInstance = nse.AddDataClass ("{5137607c-a7b7-4996-b5d7-b1b814bcecf4}")
     
    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
     
     
     
    'Get Registry Values
    strComputer = "."
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
          strComputer & "\root\default:StdRegProv")
    strKeyPath = "Software\MyKey"
    oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
          arrValueNames, arrValueTypes
    For i=0 To UBound(arrValueNames)
            Select Case arrValueTypes(i)
            Case REG_SZ
                       oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),strValue
                      'Add Row to the NSE and Set the Columns
                      dim objDataRow
                      set objDataRow = objDataClass.AddRow
                      objDataRow.SetField 0, arrValueNames(i)
                      objDataRow.SetField 1, strValue
            Case REG_EXPAND_SZ
                ' Do Nothing
            Case REG_BINARY
                ' Do Nothing
            Case REG_DWORD
                   oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i), uValue
                   'Add Row to the NSE and Set the Columns
                   dim objDataRow
                   set objDataRow = objDataClass.AddRow
                   objDataRow.SetField 0, arrValueNames(i)
                  objDataRow.SetField 1, Cstr(uValue)
            Case REG_MULTI_SZ
                ' Do Nothing
        End Select
    Next
     
    'Send the NSE
    nse.SendQueued
     

     



  • 5.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 12:04 PM

    Can you please show me a screenshot of your Attributes in the Custom Data Class for this custom inventory?  I am new to 7.1 and I'm having a hard time understanding attributes.



  • 6.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 01:20 PM
      |   view attached

    I've attached a screenshot



  • 7.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 01:39 PM

     

    Even thought you are grabbing information like below, you only need two attributes?
     
    [HKEY_LOCAL_MACHINE\SOFTWARE\MyKey]
    "ImageCutDate"="5/11/11"
    "ImageVersion"="Windows 7 Pro SP1"
    "Win7Revision"="2"
    "Win7"="1"
    "SP1"="True"
    "Brand"="Lenovo"
    "Model"="T420s"
    "Type"="Laptop"


  • 8.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 01:59 PM

    Yes,

     

    All of the values such as "ImageCutDate", "ImageVersion", etc  will be placed into the Name attribute and the data such as "5/11/11", "Windows 7 Pro SP1", etc will be placed into the Value attribute.

     

    So looking at the database table I would have 2 columns

     

    Column Names-           GISName                  GISValue

                                      ImageCutDate             5/11/11

                                      ImageVersion             Windows 7 Pro SP1

                                          ...                              ...

     

    etc

     

     



  • 9.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 04:02 PM

    Thank you for all your help.  If I have to also grab the Registy Key like HKLM\Software\Test, would I then need three attributes?



  • 10.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 04:17 PM

    If you are grabbing 2 different registry hives I would say create 2 seperate data classes and have 2 seperate custom inventory scripts, 1 for each.



  • 11.  RE: Anyone have an example of a custom inv script to pull a registry hive?

    Posted Jan 07, 2013 04:38 PM

    The issue with is that the hives under HKLM\Softwar\Test are created based on the application version installed like the screenshot below.  I am very new to VBScript and 7.1 that tackling this problem is very challenging for me.