如何使用Windows任务计划程序检查特定进程(窗口任务管理器)是否正在运行


how to check specific process (window task manager) is running or not using Windows Task Scheduler?

我想创建一个Windows任务计划程序,检查rubyw.exe是否在窗口进程中运行。如果它没有运行,则Scheduler将运行一个C:''test.rb文件,如果它正在运行,则不执行任何操作

我该怎么做?在ruby和php中

好的!因此,您可以使用WMIWIN32OLE 采取以下方法

require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
processes = wmi.ExecQuery("select * from win32_process")
ar = processes.each.with_object([]) {|i,a| a << i.name }
# => ["System Idle Process", "System", "smss.exe", "csrss.exe",...]
if ar.include? "rubyw.exe"
 #run a C:/test.rb file
else
 # do nothing
end