Solved

Hosts file update with 2 records remotely.

Posted on 2011-09-18
2
410 Views
Last Modified: 2012-05-12
Hi,
Hosts file update with 2 records remotely.
I want help with a script that reads a txt file with machine names and updates all machines hosts file with 2 entries and then gives Success and failure report.

Regards
Raja
0
Comment
Question by:bsharath
2 Comments
 
LVL 18

Accepted Solution

by:
x-men earned 500 total points
ID: 36559218
'filename is expected to have one
'name per line
On Error Resume Next
Dim strFilename,strReportFile ,HostsLine1,HostsLine2,objShell, strExecutable, objFSO, objTS, Computer
strFilename = "c:\Computers.txt"
strReportFile = "C:\report.txt"
HostsLine1 = "IP.IP.IP.IP      Name"
HostsLine2 = "IP.IP.IP.IP      Name"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(strFilename)
Set objReport = objFSO.OpenTextFile(strReportFile, 8,True)

Do Until objTS.AtEndOfStream
      Computer = objTS.ReadLine
      objReport.Write Computer
      Set objHostsFile = objFSO.OpentextFile("\\"&Computer&"\c$\windows\system32\drivers\etc\hosts", 8)
            objReport.Write vbTab & Err.Number & vbTab & Err.Description
      objHostsFile.WriteLine HostsLine1
      objHostsFile.WriteLine HostsLine2
            objReport.WriteLine  vbTab & Err.Number & vbTab & Err.Description
      objHostsFile.Close
Loop
objTS.Close
objReport.Close


0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36561218
"updates all machines hosts file with 2 entries"

Do you mean adding 2 entries, or changing 2 entries?

Cheers
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now