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
Solved

Hosts file update with 2 records remotely.

Posted on 2011-09-18
2
413 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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