Video Screencast Help

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

Created: 05 Dec 2012 • Updated: 07 Dec 2012 | 10 comments
SonicGT's picture
This issue has been solved. See solution.

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.

 

Comments 10 CommentsJump to latest comment

Nelo's picture

try reading https://www-secure.symantec.com/connect/forums/custom-inventory-troubleshooting

hope it helps.

Nelo

SonicGT's picture

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.

 

SonicGT's picture

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
 

 

SOLUTION
ArthurV's picture

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.

ArthurV's picture

 

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"
SonicGT's picture

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

 

 

ArthurV's picture

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?

SonicGT's picture

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.

ArthurV's picture

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.