【发布时间】:2021-02-19 21:05:29
【问题描述】:
我正在编写一个 VBS 脚本,它会要求用户输入他们想要阻止的网站的地址,然后他们输入的内容将被添加到他们计算机的主机文件中,从而使个人能够无法访问该特定网站。
换句话说,我想将输入框函数的答案插入到一个数组中,然后将该数组中的字符串导出到另一个文件中。
这是我现在的代码,它除了询问输入框给出的两个问题之外什么都不做——它不会将输入框的内容写入主机文件。究竟出了什么问题,我该如何解决?
非常感谢您的回答
dim result
dim sites
x = 0
Do
Set sites = CreateObject("System.Collections.ArrayList")
result = Inputbox("What site do you wanted blocked? Please include entire address.")
result2 = MsgBox("Would you like to add another site at this time?", vbQuestion + vbYesNo)
If result2 = vbNo Then
Exit Do
End If
sites.add result
Loop
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Hosts = FSO.GetFile("C:\Windows\System32\drivers\etc\hosts")
set oapp = FSO.OpenTextFile("C:\Windows\System32\drivers\etc\hosts", 8, true)
for x = 0 to sites.Count -1
site = sites(x).ToString
oapp.WriteLine ("0.0.0.0" & site)
next
【问题讨论】: