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

StackOverflow https://stackoverflow.com/questions/17469368

سؤال

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