Question : For i=0 to UBOUND(RegValueName) Type Mismatch: 'UBOUND'

I am looking to read a array of Registry Value Names and Delete them.
The first run works since there are values, but after that I get the error.
Once they are deleted the second run of the script returns an error
Type Mismatch: 'UBOUND'
Since the Subkey have no values after the first run the Array is returning a Null value if I am correct.
 
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
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
 
strComputer = "."

 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
 
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,arrValueNames, arrValueTypes


For i=0 To UBound(arrValueNames)
if instr(arrValueNames(i),"SusClientId") then
   
'Msgbox(arrValueNames(i))

oReg.DeleteValue HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames(i)
end if
Next

Answer : For i=0 to UBOUND(RegValueName) Type Mismatch: 'UBOUND'



oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,arrValueNames, arrValueTypes
 
'add this
If Not IsNull(arrValueNames) Then
  For i=0 To UBound(arrValueNames)
  if instr(arrValueNames(i),"SusClientId") then
   
  'Msgbox(arrValueNames(i))
 
  oReg.DeleteValue HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames(i)
  end if
  Next
End If
Random Solutions  
 
programming4us programming4us