Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top