欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-21 16:26:37
复制代码 代码如下: sub download(url,target) const adtypebinary = 1 const adtypetext = 2 co...

复制代码 代码如下:

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

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