我不时需要编辑远程计算机上的主机文件。如果我可以使用快速的vbscript,这将使事情变得更容易。我正在处理的脚本没有进行更改,我不太清楚为什么。
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 & "\Windows\System32\Drivers\etc\Hosts"
Set filetxt = fso.OpenTextFile(HostsFile, ForAppending, True)
DNSEntry = inputbox("Enter the DNS entry" & vbCrLf & "ex: 192.168.0.2 domain.com","DNSEntry")
If DNSEntry = "" Then
WScript.quit
Else
filetxt.WriteLine(DNSEntry)
filetxt.Close
End If
WScript.quit
答案 0 :(得分:2)
如果您计划使用管理共享,请更改此行:
HostsFile = strComputer & "\Windows\System32\Drivers\etc\Hosts"
到
HostsFile = "\\" & strComputer & "\c$\Windows\System32\Drivers\etc\Hosts"