如何运行循环检查特定运行进程的 vbs?还是缺少流程? [英] How to run loop check vbs for particular running process? Or missing process?

查看:19
本文介绍了如何运行循环检查特定运行进程的 vbs?还是缺少流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下 VBScript (check.vbs):

I am running the following VBScript (check.vbs):

Set service = GetObject ("winmgmts:")

For Each Process In Service.InstancesOf("Win32_Process")
    If Process.Name = "cmd.exe" Then
        WScript.Echo "cmd running"
        WScript.Quit
    End If
Next
CreateObject("WScript.Shell").Run("C:\system\file.bat")

此脚本将检查 cmd.exe 是否正在运行.如果它正在运行,此脚本将显示一条消息cmd running".如果它没有运行,这个脚本将打开一个批处理文件C:\system\file.bat.

This script will check whether cmd.exe is running or not. If it is running, this script will display a message "cmd running". If it is not running, this script will open a batch file C:\system\file.bat.

但我真正需要的是:当我运行这个脚本 check.vbs 时,它需要继续检查,直到发现 cmd.exe 没有运行.

But what I actually need is: when I run this script check.vbs it needs to keep on checking until it finds that cmd.exe is not running.

只有当它发现 cmd.exe 没有运行时,它才需要运行 file.bat - 在后台重复检查后(就像任何循环程序一样).

Only if it found cmd.exe is not running it needs to run file.bat - after repeated checking in background (like any loop program).

简单来说,在打开check.vbs时,脚本需要不断检查cmd.exe是否正在运行,一旦它发现它没有运行,需要打开file.bat.

In simple words, when opening check.vbs the script need to continously check that cmd.exe is running or not, once it found it's not running, it need to open file.bat.

推荐答案

仍然不确定我是否正确理解问题,但假设您确实想要一个监视并重新生成特定进程的监视器,您可以执行以下操作:

Still not sure if I understand the question correctly, but assuming that you actually want a monitor that watches and re-spawns a particular process you could do something like this:

Set wmi = GetObject ("winmgmts://./root/civm2")

Sub CheckProcess(name, script)
    For Each p In wmi.ExecQuery("SELECT * FROM Win32_Process")
        If p.Name = name Then Exit Sub
    Next
    CreateObject("WScript.Shell").Run script
End Sub

Do
    CheckProcess "cmd.exe", "C:\system\file.bat"
    WScript.Sleep 100
Loop

这篇关于如何运行循环检查特定运行进程的 vbs?还是缺少流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆