[英]Adding and Exporting strings in array with VBS script
我正在開發一個 VBS 腳本,它會要求用戶輸入他們想要阻止的網站的地址,然后他們輸入的內容將被添加到他們計算機的主機文件中,從而使個人無法訪問該特定網站。
換句話說,我想將輸入框 function 的答案插入到一個數組中,然后將該數組中的字符串導出到另一個文件中。
這是我現在的代碼,它除了詢問輸入框給出的兩個問題之外什么都不做——它不會將輸入框的內容寫入主機文件。 究竟出了什么問題,我該如何解決?
非常感謝您的回答
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
arraylist站點應該在循環之前初始化,否則它總是被重置。
sites.add應該放在Exit Do之前,否則最后的結果將不包括在內。
Dim result
Dim sites
Set sites = CreateObject("System.Collections.ArrayList")
Do
result = Inputbox("What site do you wanted blocked? Please include entire address.")
sites.add result
result2 = MsgBox("Would you like to add another site at this time?", vbQuestion + vbYesNo)
If result2 = vbNo Then
Exit Do
End If
Loop
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oapp = FSO.OpenTextFile("C:\Windows\System32\drivers\etc\hosts", 8, true)
For x = 0 to sites.Count -1
site = sites(x)
oapp.WriteLine ("0.0.0.0 " & site)
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.