Solved

Hosts file update with 2 records remotely.

Posted on 2011-09-18
2
404 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
Comment Utility
'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
Comment Utility
"updates all machines hosts file with 2 entries"

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

Cheers
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

762 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

10 Experts available now in Live!

Get 1:1 Help Now