VBS - 我可以退出一个重复自身的 VBS 消息框而不去任务管理器或 cmd 吗?

VBS- Can I exit a VBS message box that repeats itself without going to the task manager or cmd?

我有一个消息框,只要您单击“确定”,它就会自动重复 - 顺便说一下,这是唯一的选项。
我的代码:

    'Very Annoying script'   
Set objShell = CreateObject("Wscript.Shell")

intMessage = Msgbox("Click ok to say yes",16, "Is this messagebox annoying?")

If intMessage = vbOK Then
    RETRY
Else
Wscript.Quit
End If
SUB RETRY
'Very Annoying script'   
Set objShell = CreateObject("Wscript.Shell")

intMessage = Msgbox("Click ok to say yes",16, "Is this messagebox annoying?")

If intMessage = vbOK Then
    RETRY
Else
Wscript.Quit
End If
End sub

我可以在不结束标记为 Microosft Windows based Script Host 的进程的情况下结束以下脚本吗? 这不包括 运行 cmd 行(它不会工作)

    taskkill /im wscript.exe

转到任务管理器。

结束脚本的唯一方法是使用

    taskkill /f /im wscript.exe


除此之外,它将简单地重新运行脚本(与您只需单击确定时的效果相同)

感谢姜YD的解答

如果你使用这个命令taskkill /IM wscript.exe /F;你杀死了所有的 运行 vbscript,但是 如果你有很多 运行 脚本在不同路径的循环中,你可以使用这个 vbscript 来选择要杀死或不杀死哪个。所以这个脚本的目的是 select 并专注于您想要杀死的进程,您也可以将其保存在日志文件中。 试一试 ;)

Option Explicit
Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count,strComputer
If AppPrevInstance() Then 
    MsgBox "Il y a une instance déjà en cours" & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,"Il y a une instance déjà en cours"    
    WScript.Quit   
Else 
Copyright = "[© Hackoo © 2015 ]"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject( "Wscript.Shell" )
NomFichierLog="Killed Process.txt"
temp = ws.ExpandEnvironmentStrings("%temp%")
PathNomFichierLog = temp & "\" & NomFichierLog
Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1)
strComputer = "."
    Call Find("wscript.exe")
    Call Explorer(PathNomFichierLog)
End If
'***************************************************************************************************
Function Explorer(File)
    Dim ws
    Set ws = CreateObject("wscript.shell")
    ws.run "Explorer "& File & "\",1,True
end Function
'***************************************************************************************************
Sub Find(MyProcess)
    Dim colItems,objItem,Processus,Question
    Titre = " Processus "& DblQuote(MyProcess) &" en cours d'exécution "
    Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
    & "Where Name like '%"& MyProcess &"%' AND NOT commandline like " & CommandLineLike(WScript.ScriptFullName) & "",,48)
    Count = 0 
    For Each objItem in colItems
        Count= Count + 1
        'Processus = Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) 'Extraction du chemin du script en ligne de commande
        Processus = objItem.CommandLine 'Replace(Processus,chr(34),"")
        Question = MsgBox ("Voulez-vous arrêter ce script : " & DblQuote(Processus) & " ?" ,VBYesNO+VbQuestion,Titre+Copyright)
        If Question = VbYes then
            objItem.Terminate(0)'Tuer ce processus
            OutPut.WriteLine Processus
        else
            Count= Count - 1 'décrementer le compteur de -1
        End if
    Next
OutPut.WriteLine String(100,"*")
OutPut.WriteLine count & Titre & "ont été arrêtés"
OutPut.WriteLine String(100,"*") & VbCrLF 
End Sub
'**************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************
Function AppPrevInstance()   
    With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\.\root\cimv2")   
        With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
            " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")   
            AppPrevInstance = (.Count > 1)   
        End With   
    End With   
End Function   
'**************************************************************************
Sub Pause(Minutes)    
    Wscript.Sleep(Minutes*1000*60)    
End Sub   
'**************************************************************************
Function StripProcPath(ProcessPath)   
    Dim arrStr : arrStr = Split(ProcessPath, "\")   
    StripProcPath = arrStr(UBound(arrStr))   
End Function   
'**************************************************************************
Function CommandLineLike(ProcessPath)   
    ProcessPath = Replace(ProcessPath, "\", "\")   
    CommandLineLike = "'%" & ProcessPath & "%'"   
End Function
'**************************************************************************