VBS命令-进程操作代码(检测进程, 结束进程)

//检测进程

进程名 = "qq.exe"

返回值 = IsProcess(进程名)

If 返回值 = True Then

    MessageBox "发现进程"

ElseIf 返回值 = False Then

    MessageBox "没有发现进程"

End If

//检测进程 优化后的代码

If IsProcess("qq.exe") = True Then 

    MessageBox "发现进程"

Else 

    MessageBox "没有发现进程"

End If

//检测进程组

进程组 = "qq.exe|notepad.exe"

返回值 = IsProcessEx(进程组)

If 返回值 = True Then

    MessageBox "发现进程"

ElseIf 返回值 = False Then

    MessageBox "没有发现进程"

End If

//检测进程组 优化后的代码

If IsProcessEx("qq.exe|notepad.exe") = True Then 

    MessageBox "发现进程"

Else 

    MessageBox "没有发现进程"

End If

//结束进程 前台执行

进程名 = "qq.exe"

    Call CloseProcess(进程名, 1)

//结束进程 后台执行

进程名 = "qq.exe"

    Call CloseProcess(进程名, 0)

    //结束进程组 前台执行

进程组 = "qq.exe|notepad.exe"

    Call CloseProcessEx(进程组, 1)

//结束进程组 后台执行

进程组 = "qq.exe|notepad.exe"

    Call CloseProcessEx(进程组, 0)

//实例应用 结束进程 前台执行 10秒超时

进程名 = "qq.exe"

For 10

    Call CloseProcess(进程名,1)

    Delay 1000

    返回值 = IsProcess(进程名)

    If 返回值 = False Then

        Exit For

    End If

Next

If 返回值=True Then

    MessageBox "结束进程失败"

Else

    MessageBox "结束进程成功"

End If

//实例应用 结束进程 前台执行 优化后的代码(直到型循环) 有些进程VBS检测不到 所以先关闭后检测

Do

    Call CloseProcess("qq.exe",1)

    Delay 1000

Loop While IsProcess("qq.exe")=True

MessageBox "结束进程成功"

//实例应用 结束进程组 后台执行 10秒超时

进程组 = "qq.exe|notepad.exe"

For 10

    Call CloseProcessEx(进程组,0)

    Delay 1000

    返回值 = IsProcessEx(进程组)

    If 返回值 = False Then

        Exit For

    End If

Next

If 返回值=True Then

    MessageBox "结束进程失败"

Else

    MessageBox "结束进程成功"

End If

//实例应用 结束进程组 后台执行 优化后的代码(直到型循环) 有些进程VBS检测不到 所以先关闭后检测

Do

    Call CloseProcessEx( "qq.exe|notepad.exe",0)

    Delay 1000

Loop While IsProcessEx( "qq.exe|notepad.exe")=True

MessageBox "结束进程成功"

//函数 子程序部分代码

//检测进程

Function IsProcess(ExeName)

    Dim WMI, Obj, Objs,i

    IsProcess = False

    Set WMI = GetObject("WinMgmts:")

    Set Objs = WMI.InstancesOf("Win32_Process")

    For Each Obj In Objs

        If InStr(UCase(ExeName),UCase(Obj.Description)) <> 0 Then

            IsProcess = True

            Exit For

        End If

    Next

    Set Objs = Nothing

    Set WMI = Nothing

End Function

//结束进程

Sub CloseProcess(ExeName,RunMode)

    dim ws

    Set ws = createobject("Wscript.Shell")

    ws.run "cmd.exe /C Taskkill /f /im " & ExeName,RunMode

    Set ws = Nothing

End Sub

//检测进程组

Function IsProcessEx(ExeName)

    Dim WMI, Obj, Objs,ProcessName,i

    IsProcessEx = False

    Set WMI = GetObject("WinMgmts:")

    Set Objs = WMI.InstancesOf("Win32_Process")

    ProcessName=Split(ExeName,"|")

    For Each Obj In Objs

        For i=0 to UBound(ProcessName)

            If InStr(UCase(ProcessName(i)),UCase(Obj.Description)) <> 0 Then

                IsProcessEx = True

                Exit For

            End If

        Next

    Next

    Set Objs = Nothing

    Set WMI = Nothing

End Function

//结束进程组

Sub CloseProcessEx(ExeName,RunMode)

    dim ws,ProcessName,CmdCode,i

    ProcessName = Split(ExeName, "|")

    For i=0 to UBound(ProcessName)

        CmdCode=CmdCode & " /im " & ProcessName(i)

    Next

    Set ws = createobject("Wscript.Shell")

    ws.run "cmd.exe /C Taskkill /f" & CmdCode,RunMode

    Set ws = Nothing

End Sub

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值