I want to create a Windows Task Scheduler that will check whether rubyw.exe is running or not in window processes . if it is not running then Scheduler will run a C:/test.rb file and if it is running then do nothing.

how can i do it? in ruby and php

有帮助吗?

解决方案

Okay! So you can take the approach as below using WMI and WIN32OLE

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top