我做了一些代码来测试一个进程和一个进程列表。我自己做了一些事,但我不知道在哪里建立另一个过程。请查看下面的图片和代码。我希望我写清楚。
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrProcesses : arrProcesses = Split(objFSO.OpenTextFile("C:\Project\list_processes.txt").ReadAll, vbCrLf)
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim colProcesses : Set colProcesses = objWMIService.ExecQuery(_
"SELECT Name FROM Win32_Process WHERE Name = '" & Join(arrProcesses, "' OR Name = '") & "'")
If colProcesses.Count > 0 Then
Set WshShell = WScript.CreateObject("WScript.Shell")
Command = "Command 1"
WshShell.Run Command
Else
Set WshShell = WScript.CreateObject("WScript.Shell")
Command = "Command 2"
WshShell.Run Command
End If
答案 0 :(得分:1)
为您的特定流程添加另一个查找:
pname = "Process 1"
Set p = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='" & pname & "'")
If p.Count > 0 And colProcesses.Count > 0 Then
'do something
Else
'do other
End If
确保"流程1"如果您的条件是"进程1并且列表中的任何其他进程正在运行,则arrProcesses
不在ModuleCache
。