如何从VBS应用中删除弹出消息

时间:2018-07-06 07:53:19

标签: vbscript silent

我下载了此vbs脚本,该脚本旨在阻止浪费时间的网站,例如Facebook和YouTube。它工作得很好,但我希望它完全安静地运行。当执行该应用程序时,出现Wscript消息,询问我是否要运行该文件,单击“是”后,出现另一条消息,表明网站已被阻止。

在检查了代码之后,我注释掉了表明网站已被阻止/未阻止的消息,这阻止了它们出现,但随后这些网站没有被阻止。需要对代码进行什么更改,以使所有内容都不会弹出,因此其他用户无法告诉应用程序正在阻止网站。

'Add the list of time wasting websites here
WebsitesToBlock = Array("twitter.com", "www.youtube.com", "www.facebook.com")

If WScript.Arguments.length =0 Then
    Set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " RunAsAdministrator", "", "runas", 1
Else
    Const ForReading = 1, ForWriting = 2

    Set shell = CreateObject("WScript.Shell")    
    root = shell.ExpandEnvironmentStrings("%systemroot%")     
    hostFile = root & "\system32\drivers\etc\hosts"
    tempFile = hostFile & ".bak"

    blocked = 0
    towrite = false

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f1 = fso.OpenTextFile(hostFile, ForReading, True)
    Set f2 = fso.OpenTextFile(tempFile, ForWriting, True)

    Do Until f1.AtEndOfStream

        line = f1.Readline
        towrite = true

        For Each URL in WebsitesToBlock
            If instr(line, URL) Then
                If blocked = 0 Then 
                    If left(line, 1) = "#" Then blocked = 1 Else blocked = 2
                End If
            towrite = false
            End If
        Next    

        If towrite Then f2.WriteLine line
    Loop

    For Each URL in WebsitesToBlock
        If blocked <> 2 Then
            f2.WriteLine "127.0.0.1" & vbTab & vbTab & URL 
        End If
    Next

    fso.Copyfile tempFile, hostFile

    f1.Close
    f2.Close

    If blocked = 2 Then 
        WScript.echo "Time wasting websites have now been unblocked on this computer" 
    Else
        WScript.echo "Time wasting websites are now blocked on this computer!" 
    End If

End If

0 个答案:

没有答案