How to append to host file on remote machine using vbscript -
How to append to host file on remote machine using vbscript -
from time time need edit host files on remote machines. create things much easier if utilize quick vbscript this. script i'm working on isn't making changes , i'm not sure why.
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 localhost computer","get hosts file","localhost") if strcomputer = "" wscript.quit end if hostsfile = strcomputer & "\windows\system32\drivers\etc\hosts" set filetxt = fso.opentextfile(hostsfile, forappending, true) dnsentry = inputbox("enter dns entry" & vbcrlf & "ex: 192.168.0.2 domain.com","dnsentry") if dnsentry = "" wscript.quit else filetxt.writeline(dnsentry) filetxt.close end if wscript.quit
if you're planning on using administrative share, alter line:
hostsfile = strcomputer & "\windows\system32\drivers\etc\hosts" to
hostsfile = "\\" & strcomputer & "\c$\windows\system32\drivers\etc\hosts" vbscript
Comments
Post a Comment