I am trying to check if a process exists in JRuby on a Windows 7 machine. I'm trying:
require 'jwin32ole'
wmi = WIN32OLE.connect("winmgmts://")
processes = wmi.ExecQuery("select * from win32_process")
However, WIN32OLE.connect("winmgmts://")
is returning nil.
When I started up Excel, I was able to successfully call WIN32OLE.connect("Excel.Application")
, so WIN32OLE.connect can work.
Any suggestions on how to get this working, or another way to check if a process exists?
I found what looks like to be the problem.
In jwin32ole, this is the code for connect:
And looking at the API documentation for jacob.activeXComponent.connectToActiveInstance:
This will fail for any prog id with a ":" in it
Which, of course, will result in a failure while trying to connect to "winmgmts:". Why it doesn't accept colons in not explained.
Another connection method in jacob.activeXComponent would have to be directly used that doesn't have a problem with colons in the prog id.