set service = GetObject ("winmgmts:")
for each Process in Service.InstancesOf ("Win32_Process")
If Process.Name = "Progranametocheck.exe" then
wscript.echo "Progranametocheck is running"
wscript.quit
End If
next
wscript.echo "Progranametocheck is not running"
上面的代码(VBScript)的检查是一个程序正在运行,使弹出uptelling你,如果它的运行与否。如果要在程序运行运行程序替换:“wscript.echo‘Progranametocheck运行’有:
Set objShell = Nothing
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("""C:\\dir\\logger.exe""")
Set objShell = Nothing
所以一起就变成:
set service = GetObject ("winmgmts:")
for each Process in Service.InstancesOf ("Win32_Process")
If Process.Name = "Progranametocheck.exe" then
Set objShell = Nothing
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("""C:\\dir\\logger.exe""")
Set objShell = Nothing
wscript.quit
End If
next
wscript.echo "Progranametocheck is not running"