VBS 通过 HTTP 请求取数据修改 hosts
' On Error Resume Next Const strURL = "http://***.txt" Dim objXMLHTTP, objFSO ' Http get set info Set objXMLHTTP = CreateObject("Msxml2.XMLHTTP") objXMLHTTP.open "GET", strURL & "?" & Now(), False objXMLHTTP.send() If Err.Number <> 0 Then ' WScript.Echo "Error: " & Err.Number Set objXMLHTTP = Nothing Err.Clear Else WScript.Echo objXMLHTTP.responseText strHttpResult = Split(objXMLHTTP.responseText, " ") strDomainName = Trim(strHttpResult(0)) strIp = Replace(Trim(strHttpResult(1)), vbLf, "") Set objXMLHTTP = Nothing ' Update hosts Dim strNewContents Set objFSO = CreateObject("Scripting.FileSystemObject") Const ForReading = 1, ForWriting = 2, ForAppending = 8 strHostFile = objFSO.GetSpecialFolder(1) & "\drivers\etc\hosts" strHostBackFile = objFSO.GetSpecialFolder(1) & "\drivers\etc\hosts.bak" objFSO.CopyFile strHostFile, strHostBackFile Set objFile = objFSO.OpenTextFile(strHostFile, ForReading, False) Do Until objFile.AtEndOfStream strLine = objFile.Readline strLine = Trim(strLine) If Not(InStr(1, strLine, Chr(9) & strDomainName, 1) > 0 Or InStr(1, strLine, Chr(32) & strDomainName, 1) > 0) Then strNewContents = strNewContents & strLine & vbCrLf End If Loop strNewContents = strNewContents & strIp & Chr(9) & strDomainName objFile.Close Set objFile = objFSO.OpenTextFile(strHostFile, ForWriting) objFile.Write strNewContents objFile.Close Set objFSO = Nothing End If
引用
http://www.example-code.com/vb/splitComma.asp
http://zh-cn.w3support.net/index.php?db=so&id=204759
http://hi.baidu.com/officeteam/blog/item/5c4941f4be05eb2dbd310901.html
http://blog.ednchina.com/micheal/48115/message.aspx
http://www.jb51.net/article/14586.htm
http://technet.microsoft.com/zh-cn/library/ee692852.aspx#ELC
相关推荐
cbqstars 2020-08-16
未来战士 2019-12-08
架构技术交流 2019-12-17
laohyx 2019-10-23
airfling 2019-11-25
luohui 2009-07-23
大尉 2009-01-05
weiloser 2008-08-16
wesai 2019-09-05
bentengdi 2008-06-23
SometimesYmc 2008-06-20
xsjezp 2008-06-20
HTMLzuo 2019-09-05
86560895 2007-03-27
diediexiaomi 2007-03-25
潇汀 2007-03-07
以梦为马不负韶华 2007-03-07