I'm stuck... emumerate reg key's

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
irascible
Posts: 10
Joined: Wed Apr 04, 2007 4:55 am

I'm stuck... emumerate reg key's

Post by irascible »

Here is what I have so far... it works perfect if you query against a single machine; however, with multiple devices listed it fails on the majority of the devices. It appears this is caused because the function calls itself; therefore, the do loop thinks the function is complete on the first pass and continues to the next machine, calling the function again.

Any suggestions?


Const HKEY_LOCAL_MACHINE = &H80000002Const ForReading = 1sFile1 = "Devices.txt"Set objFSO = CreateObject("Scripting.FileSystemObject")Set oFile1 = objFSO.OpenTextFile(sFile1,ForReading)sKey = "SOFTWAREMicrosoftUpdates"Set objSubKey = CreateObject("Scripting.Dictionary") objSubKey.CompareMode = vbTextCompare
Do Until oFile1.AtEndOfStream strComputer = oFile1.ReadLine oDevice = strComputer & ".txt" Set oLog = objFSO.CreateTextFile(oDevice) Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "/root/default:StdRegProv") Call SearchReg(sKey)Loop
Function SearchReg(strKeyPath) strText = "KB" rKey = objReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys) If IsArray(arrSubKeys)Then For Each strSubKey In arrSubKeys SearchReg((strKeyPath & "" & strSubKey)) If InStr(strSubKey, "KB") Then If Not objSubKey.Exists(strSubKey) Then objSubKey.Add strSubKey, strSubKey oLog.WriteLine strSubKey End If End If Next Else Exit Function End IfEnd Functionirascible2007-05-29 15:55:52

User avatar
irascible
Posts: 10
Joined: Wed Apr 04, 2007 4:55 am

I'm stuck... emumerate reg key's

Post by irascible »

although I understand it's standard practice to dim an object used globablly to reserve storage space when it's going to be used within a function/sub... it's not needed, and unfortunately doesn't solve the problem.

Regardless, I did add it to the script. The same incident is occuring as I mentioned above, so hopefully someone has a solution.irascible2007-06-01 10:00:28

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

I'm stuck... emumerate reg key's

Post by jvierra »

I ran your script in a domain and had mno problems. Are you sure all of the machines can be contacted remotely?

User avatar
irascible
Posts: 10
Joined: Wed Apr 04, 2007 4:55 am

I'm stuck... emumerate reg key's

Post by irascible »

I ran your script in a domain and had mno problems. Are you sure all of the machines can be contacted remotely?


Yes, if I run the script on each machine from the same location individually it completes.

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

I'm stuck... emumerate reg key's

Post by jvierra »

The registry object is scoped global but re-used in the recursion. It needs to be scoped local to teh function so it gets recreated on each call.

Each level of teh function call has to create a new object that is defined in that instance of teh function.

This is a common recursion issue.

Locked