Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript registry

Status
Not open for further replies.

SJaeger

IS-IT--Management
Dec 5, 2018
1
0
0
US
I am using a script in Altiris to run an inventory and collect info for a custom data class. On most pcs, the script runs and gets the value and then sends to the notification server and database. On some machines, I get an error-...vbs(79,1) (null): Invalid type for data field. On these pcs, the subkey does not exist. I would like the script to either return the value that is expected or just write key not found.
SCRIPT:

'===================================================================================================================



'DESCRIPTION: Gather UEFI Secure Boot Status from client registry and send to Altiris



'===================================================================================================================



const HKEY_LOCAL_MACHINE = &H80000002



strComputer = "."

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

strKeyPath = "SYSTEM\CurrentControlSet\Control\SecureBoot\State"

strValueName1 = "UEFISecureBootEnabled"

oReg.GetDWordValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName1,Value










'===================================================================================================================

'Create instance of Altiris NSE component

dim nse

set nse = WScript.CreateObject ("Altiris.AeXNSEvent")



' Set the header data of the NSE

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

'Modify this class guid to match the one generated when you create the custom data class

set objDCInstance = nse.AddDataClass ("{64f22255-aa87-44aa-b088-5c1e93bde22f}")



dim objDataClass

set objDataClass = nse.AddDataBlock (objDCInstance)



'Add a new row

dim objDataRow

set objDataRow = objDataClass.AddRow

'Set columns

objDataRow.SetField 0, Value



'Wscript.Echo UEFISecureBootEnabled



nse.SendQueued
 
Here's how I resolve issues like yours:

[pre]On Error Resume Next
[enter code here to get your subkey]
If Err.Number <> 0 Then ShowError("Key not found")
On Error goto 0

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

Sub ShowError(strMessage)
MsgBox strMessage & vbNewline & "Error number: " & Err.Number & vbNewline & "Source: " & Err.Source & vbNewline & "Description: " & Err.Description
Err.Clear
End Sub[/pre]

This will allow you to continue without seeing the error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top