Can anyone help me close this program in VBScript?

后端 未结 3 1749
日久生厌
日久生厌 2020-12-20 10:02
MsgBox (\"Do you want to start the autoclicker?\", vbOkOnly, \"Autoclicker\")
CreateObject(\"WScript.Shell\").Run(\"\"\"C:\\         


        
相关标签:
3条回答
  • 2020-12-20 10:40
    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
    

    This kills calculator.exe. Change it to wscript.exe. You might want to check command line if you just want to kill fun.vbs.

    0 讨论(0)
  • 2020-12-20 10:52

    The following routine kills all processes whose command lines contain a specified string. The 3 lines below the routine are for testing it. We pause the routine by showing a message box and when you dismiss the message box, we kill the script instance, so the second message box doesn't show up. When you use it, you want to replace the last 3 lines with

    KillProcesses "Fun.vbs"
    

    I'd be careful using this and specify as much of the command line as possible to make sure I absolutely, positively match only the processes I want to terminate. You can modify the Task Manager and add a column to show the command line for every running process. In the routine below, the search in command line is case-insensitive.

    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"
    
    0 讨论(0)
  • 2020-12-20 11:03

    I made before a script that ask you what vbscript did you want to kill and log the result into file.

    So just, give a try :

    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
    '**********************************************************************************************
    
    0 讨论(0)
提交回复
热议问题