【问题标题】:Can anyone help me close this program in VBScript?谁能帮我在 VBScript 中关闭这个程序?
【发布时间】:2016-03-20 22:00:07
【问题描述】:
MsgBox ("Do you want to start the autoclicker?", vbOkOnly, "Autoclicker")
CreateObject("WScript.Shell").Run("""C:\Users\Henry\Desktop\Fun.vbs""")
MsgBox ("Do you want to stop the autoclicker?", vbOkOnly, "Autoclicker")

【问题讨论】:

  • 更好的代码格式。对代码的预期用途进行更长的描述会很有帮助。

标签: vbscript


【解决方案1】:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")

For Each objItem in colItems
    'msgbox objItem.ProcessID & " " & objItem.CommandLine
    If objItem.name = "Calculator.exe" then objItem.terminate
Next

这会杀死calculator.exe。将其更改为 wscript.exe。如果您只想杀死 fun.vbs,您可能需要检查命令行。

【讨论】:

  • 谢谢你,这真的很有帮助
【解决方案2】:

以下例程将终止其命令行包含指定字符串的所有进程。例程下面的 3 行用于测试它。我们通过显示一个消息框来暂停例程,当您关闭消息框时,我们会终止脚本实例,因此第二个消息框不会出现。使用的时候,要把最后3行替换成

KillProcesses "Fun.vbs"

我会小心使用它并尽可能多地指定命令行,以确保我绝对、肯定地只匹配我想要终止的进程。您可以修改任务管理器并添加一列以显示每个正在运行的进程的命令行。在下面的例程中,命令行中的搜索不区分大小写。

Option Explicit

Sub KillProcesses(strPartOfCommandLine)
    Dim colProcesses
    Dim objProcess
    Dim lReturn


    ' Get list of running processes using WMI
    Set colProcesses = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * From Win32_Process")

    For Each objProcess in colProcesses
        If (Instr(1, objProcess.Commandline, strPartOfCommandLine, vbTextCompare) <> 0) Then
            lReturn = objProcess.Terminate(0)
        End If
    Next
End Sub

Msgbox "Before being killed"
KillProcesses "KillProcesses.vbs"
Msgbox "After being killed"

【讨论】:

    【解决方案3】:

    我之前制作了一个脚本,询问你想要杀死什么 vbscript 并将结果记录到文件中。

    所以,试一试吧:

    Option Explicit
    Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count,strComputer
    Copyright = "[© Hackoo © 2014 ]"
    Titre = " Process "& DblQuote("Wscript.exe") &" running "
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ws = CreateObject( "Wscript.Shell" )
    NomFichierLog="Process_WScript.txt"
    temp = ws.ExpandEnvironmentStrings("%temp%")
    PathNomFichierLog = temp & "\" & NomFichierLog
    Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1)
    Count = 0 
    strComputer = "."
    Call Find("wscript.exe")
    Call Explorer(PathNomFichierLog)
    '***************************************************************************************************
    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
        Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
        & "Where Name like '%"& MyProcess &"%' AND NOT commandline like '%" & wsh.scriptname & "%'",,48)
        For Each objItem in colItems
            Count= Count + 1
            Processus = Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) 'Extraction of the commandline script path
            Processus = Replace(Processus,chr(34),"")
            Question = MsgBox ("Did you want to stop this script : "& DblQuote(Processus) &" ?" ,VBYesNO+VbQuestion,Titre+Copyright)
            If Question = VbYes then
                objItem.Terminate(0)'Kill this process
                OutPut.WriteLine DblQuote(Processus)
            else
                Count= Count - 1 'decrement the counter -1
            End if
        Next
    OutPut.WriteLine String(100,"*")
    OutPut.WriteLine count & Titre & " were stopped !"
    End Sub
    '**********************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '**********************************************************************************************
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      相关资源
      最近更新 更多