The purpose of this script was to allow me to quickly change the WSUS intranet server (I'm not fully done with it yet), instead of using the local Group Policy. Sometimes the WindowsUpdate key does not exist. Rather than guessing and writing a new one, I'd rather check if it exists, and only write if it doesn't. The problem I've had is I get "Object is not a collection" when I use EnumKey. From what I know, null values are causing the error, but I don't know how to resolve it.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows"
Wscript.Echo "This program serves to connect you to your intranet WSUS server. It will create or modify the registry."
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
bFound = (lcase(subkey) = lcase(regkey))
if bFound then exit for
Next
if bFound then
Wscript.echo "'WindowsUpdate' exists."
'Continue script without creating a key named WindowsUpdate.
Else
'Since key did not exist, create key and then continue.The problem code is underlined (Line 10 for me).