通過(guò)vbs獲取遠(yuǎn)程host文件并保存到指定目錄

字號(hào):


    最近需要訪(fǎng)問(wèn)google聯(lián)盟后臺(tái),但經(jīng)常無(wú)法訪(fǎng)問(wèn),看到有網(wǎng)友提供了一份vbs版本的獲取host并保存到指定目錄的代碼,特分享下
    代碼如下:
    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ò)問(wèn)題,可能獲取會(huì)超時(shí),建議大家多運(yùn)行幾次?;蚣尤肽_本可執(zhí)行時(shí)間。