通過vbs獲取遠(yuǎn)程host文件并保存到指定目錄
更新時(shí)間:2014年12月17日 23:04:59 投稿:mdxy-dxy
最近需要訪問google聯(lián)盟后臺(tái),但經(jīng)常無法訪問,看到有網(wǎng)友提供了一份vbs版本的獲取host并保存到指定目錄的代碼,特分享下
復(fù)制代碼 代碼如下:
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
經(jīng)測(cè)試,由于網(wǎng)絡(luò)問題,可能獲取會(huì)超時(shí),建議大家多運(yùn)行幾次。或加入腳本可執(zhí)行時(shí)間。
相關(guān)文章
VBS教程:VBScript 基礎(chǔ)-VBScript 變量
VBScript只有一種數(shù)據(jù)類型 —— Variant,它是根據(jù)上下文來判斷是數(shù)字還是字符串。因?yàn)閂ariant是VBScript中唯一的數(shù)據(jù)類型,所以它也是VBScript中所有函數(shù)的返回值的數(shù)據(jù)類型2006-11-11

