Solved

vbs script to read registry values on remote computers and write the results in a csv or txt file

Posted on 2014-02-18
4
4,780 Views
Last Modified: 2014-02-18
I like this script below but instead of having to type the machine name one at a time with strComputer = InputBox("Enter the Name of the Remote PC: ")
I would like to just put all of my servers in a txt file and have it run this script against all servers in the list



' Set the constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8

' Create FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\temp\environment_variables.txt", ForAppending, True)


strComputer = InputBox("Enter the Name of the Remote PC: ")
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

objTextFile.WriteLine("PC Name: " & strComputer)
 
strKeyPath = "Software\SYMANTEC\Symantec Endpoint Protection\SMC"
strValueName = "ProductVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'Wscript.Echo "Current ProducVersion Value: " & strValue
objTextFile.WriteLine("Current ProductVersion Value: " & strValue)
 
 


objTextFile.WriteLine(vbCrLf)

objTextFile.Close
0
Comment
Question by:scriptz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 39868868
A simple loop should do the trick...

' Set the constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8

' Create FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("c:\temp\environment_variables.txt", ForAppending, True)

arrComputers = Split(objFSO.OpenTextFile("c:\temp\myComputers.txt").ReadAll, vbNewLine)

for each strComputer in arrComputers
  wscript.echo "Examining " & strComputer
  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  objFile.WriteLine "PC Name: " & strComputer
 
  strKeyPath = "Software\SYMANTEC\Symantec Endpoint Protection\SMC"
  strValueName = "ProductVersion"
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  'Wscript.Echo "Current ProducVersion Value: " & strValue
  objFile.WriteLine("Current ProductVersion Value: " & strValue)
  objFile.WriteLine(vbCrLf)
next 

objFile.Close

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39868876
Your source text file should contain a single computer name on each line of the file:

computer1
computer2
[etc]
0
 

Author Closing Comment

by:scriptz
ID: 39869037
This is exactly what I was looking for. Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39869121
Happy to help - thanks for the grade! :^)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question