title: How to append to host file on remote machine using vbscript
body: <p>From time to time I need to edit host files on remote machines. It would make things much easier if I could use a quick vbscript for this. The script that I'm working on isn't making the changes and I'm not too sure why. </p>
  
  <pre><code>on error resume next
  Const ForReading = 1, ForWriting = 2, ForAppending = 8 
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell=CreateObject("WScript.Shell")
  strComputer   = inputbox("Enter remote computer name or leave as localhost for this computer","Get Hosts file","Localhost")
  If strComputer = "" Then
      WScript.Quit
  End If
  
  HostsFile = strComputer &amp; "\Windows\System32\Drivers\etc\Hosts" 
  
  Set filetxt = fso.OpenTextFile(HostsFile, ForAppending, True)
  DNSEntry = inputbox("Enter the DNS entry" &amp; vbCrLf &amp; "ex: 192.168.0.2         domain.com","DNSEntry")
  If DNSEntry = "" Then
      WScript.quit
  Else
  filetxt.WriteLine(DNSEntry)
  filetxt.Close 
  End If
  
  WScript.quit
  </code></pre>