脚本专栏 
首页 > 脚本专栏 > 浏览文章

通过vbs获取远程host文件并保存到指定目录

(编辑:jimmy 日期: 2024/10/18 浏览:3 次 )

复制代码 代码如下:
Sub download(url,target)
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Dim http,ado
Set http = CreateObject("Msxml2.ServerXMLHTTP")
http.SetOption 2,13056
http.open "GET",url,False
http.send
Set ado = createobject("Adodb.Stream")
ado.Type = adTypeBinary
ado.Open
ado.Write http.responseBody
ado.SaveToFile target,adSaveCreateOverWrite
ado.Close
End Sub
Set WshShell=CreateObject("WScript.Shell")
WinDir =WshShell.ExpandEnvironmentStrings("%WinDir%")
HostsFile = WinDir & "\System32\Drivers\etc\Hosts_google"
Const hosts="https://raw.githubusercontent.com/vokins/simpleu/master/hosts"
download hosts,HostsFile

经测试,由于网络问题,可能获取会超时,建议大家多运行几次。或加入脚本可执行时间。

上一篇:vbs脚本实现修改DNS和清空IE临时文件功能
下一篇:使用vbscript生成36进制自动增长序号的实现代码