Check for Registry Keys on Remote Computers with VBScript

December 9, 2008 14:35 by randy

I guess this would be Part 2 on VBScripting – for today.

In the first post, Check Running Processes on Remote Computers with VBScript, I outlined a VBScript process to determine if a specific process was running on a remote computer on the same network.

In this post, I have a VBScript that will scan the registry of remote computers on the same network for a specific registry key.  List the remote processes script, this process utilizes a file containing a list of all machines on the network.  The registry key name is a local variable. It would not be too hard to take this script and put it into a function and pass the registry key name (and machine list file name for that matter) as a parameter.

This script also utilizes Scripting API for WMI to interrogate the remote machine.

Take a look.

' Set up some Constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8
Const ForReading = 1
 
' Build the date tag for the log file name
sDate = right("00" & cstr(month(date())),2) & right("00" & cstr(day(date())),2) & right("200" & cstr(year(date())),4) & right("00" & cstr(hour(time)),2) & right("00" & cstr(minute(time)),2) & right("00" & cstr(second(time)),2)
' Build the full log file name
sOutFileName = "C:\Temp\reg_scan_log_" & sDate & ".txt"
 
' set this to the registry key to search
sKeyPath = "SYSTEM\CurrentControlSet\Services"
 
' Get the FSO moving
Set oFSO = CreateObject("Scripting.FileSystemObject")
 
' Open the file with containing all of the computers to scan (name or IP address)
Set objTextFile_List = oFSO.OpenTextFile ("C:\Temp\machineList.txt", ForReading)
' Create and open the file for logging
Set objTextFile = oFSO.OpenTextFile(sOutFileName, ForAppending, True)
 
' Loop through the file containing machine names/IP addresses
Do Until objTextFile_List.AtEndOfStream
    sMachine = objTextFile_List.Readline
 
 
    Set WshShell = CreateObject("WScript.Shell")
    bPing = Not CBool(WshShell.run("ping -n 1 " & sMachine, 0, True))      
 
    If bPing = True Then         
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sMachine & "\root\default:StdRegProv")
         
        ' Create an enum of the key values
        oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrValueNames, arrValueTypes
         
        ' duh 
        ON ERROR RESUME NEXT
        
        ' check the array count
        If UBound(arrValueNames) > 0 Then
            objTextFile.WriteLine(sMachine & ": " & cstr(UBound(arrValueNames)))
        End If
        
        ' write the error message
        If err.number > 0 Then
            objTextFile.WriteLine(sMachine & ": " & err.Description)
        End If
 
    Else
        ' Set the appropriate response
        objTextFile.WriteLine(sMachine & ": Not on network")
    End If
 
loop

Thanks for listening


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading