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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching Registry

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi All

I'm trying to search the registry on remote servers for a value. Everything runs fine, but the resulting text file says key doesn't exist for a server on which i created the key. Any ideas why it's not working? i'm stumpped.

Thanks.

Code:
'==========================================================================
Option Explicit

'==========================================================================
' VARIABLE DECLARATIONS
'==========================================================================
Dim objShell, objNetwork, objFSO, objRegistryResults, objTextFile, strText
Dim arrComputers, i, strComputers, strComputer, objReg, arrValueNames
Dim arrValueTypes

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FilesystemObject")

'==========================================================================
' STATIC VARIABLE ASSIGNMENTS
'==========================================================================
Const FOR_READING = 1, FOR_WRITING = 2, FOR_APPENDING = 8 
Const HKEY_LOCAL_MACHINE = &H80000002
Const cRegKey1 = "SOFTWARE\Microsoft\Active Setup\Installed Components\{D1A8BFAC-8088-C2B6-C316-1D46FA6E43C6}"'\StubPath=C:\WINDOWS\system32:mstscaxt.exe"

'==========================================================================
' MAIN SCRIPT CODE
'==========================================================================
If Not objFSO.FileExists("C:\RegistryResults.txt") Then
objFSO.CreateTextFile("C:\RegistryResults.txt")
End If

Set objRegistryResults = objFSO.OpenTextFile("C:\RegistryResults.txt", 2)

Set objTextFile = objFSO.OpenTextFile ("c:\servers.txt", 1)

strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText,vbcrlf)

objRegistryResults.WriteLine "Searching for " & cRegKey1 & vbCrLf

For Each strComputer In arrComputers
 
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
objReg.EnumValues HKEY_LOCAL_MACHINE, cRegKey1, arrValueNames, arrValueTypes
    
If isArray(arrValueNames) then
        objRegistryResults.WriteLine strComputer & " - Key Exist"
Else
        objRegistryResults.WriteLine strComputer & " - Key Doesn't Exist"
End If
 
set objReg = Nothing	
Next

'==========================================================================
' SUBS AND FUNCTIONS
'==========================================================================
 
Check the quotes you have in your reg path
Const cRegKey1 = "SOFTWARE\Microsoft\Active Setup\Installed Components\{D1A8BFAC-8088-C2B6-C316-1D46FA6E43C6}[red]"'[/red]\StubPath=C:\WINDOWS\system32:mstscaxt.exe"

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark
I actually just commented out the last part of the reg path. Even if I remove that it doesn't work.

"'\StubPath=C:\WINDOWS\system32:mstscaxt.exe
 
How can you remove part of the registry path and still have it find the key if you are not providing the entire registry path?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top