我使用OpenTextFile
时收到错误。
错误报告的行是这一行:
Set outFile = fso.OpenTextFile(saveToFile, 2, True)
这是我的代码:
Option Explicit
Dim File, strTest, RegExp, saveToFile, fso, outFile, strReplace, objShell
Set objShell = CreateObject("WScript.Shell")
saveToFile = objShell.ExpandEnvironmentStrings("C:\Program Files (x86)\Acrylic DNS Proxy\AcrylicHosts.txt")
Set File = CreateObject("MSXML2.XMLHTTP")
File.Open "GET","https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt", False
File.Send
If File.Status = 200 Then
'Replace content for DNS server
strTest = File.responseText
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.IgnoreCase = True
RegExp.Global = True
'For Acrylic_DNS_server
RegExp.Pattern = "address=/(.*?)/(\d{1,3}(?:\.\d{1,3}){3})"
strReplace = "$2 >$1"
strTest = RegExp.Replace(strTest, strReplace)
Set RegExp = Nothing
'Write content
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.OpenTextFile(saveToFile, 2, True)
outFile.Write strTest
outFile.Close
' Clean cache DNS
objShell.Run("cmd /c psexec \\ -s ipconfig /flushdns >> & hostName, True")
ElseIf File.Status = 404 Then
MsgBox "Update_Wildcard_DNS_Acrylic_server.vbs : File Not Found : " & File.Status,vbCritical, "Update_Wildcard_DNS_Acrylic_server.vbs : Error File Not Found"
Else
MsgBox "Update_Wildcard_DNS_Acrylic_server.vbs : Unknown Error : " & File.Status,vbCritical, "Update_Wildcard_DNS_Acrylic_server.vbs : Error getting file"
End If