So, I’m trying to figure out how to automate various programs using
ruby, and feeling a bit over my head at the moment. I’m still pretty
new to ruby and programming, so maybe this is beyond me, but its the #1
reason I decided to learn ruby in the first place.
What I’m wondering is…where to start? I believe I’m right in the fact
that I need to be using WIN32OLE, but beyond that I can’t seem to get
anywhere.
How do you determine what the exact name of the program is that you need
to pass as a parameter when creating a new WIN32OLE
object(‘WhatProgramNameHere.Application’)? How do you find what methods
can be used with that specific program? Am I even right in assuming I
should be using WIN32OLE? If someone would be so kind as to steer me in
the right direction with some tips or reading material I’d be eternally
grateful.
How do you determine what the exact name of the program is that you need
to pass as a parameter when creating a new WIN32OLE
object(‘WhatProgramNameHere.Application’)? How do you find what methods
can be used with that specific program? Am I even right in assuming I
should be using WIN32OLE?
I don’t know if there are any alternatives, but for automation on
Windows, OLE is the way to go.
As for information, you’re looking for OLE interface documentation. If
you want it for Microsoft applications, then look at the MSDN
documentation at http://msdn.microsoft.com/. For example, if you
wanted to automate Outlook 2007, you would look at http://msdn.microsoft.com/en-us/library/bb176619.aspx. Note that
when you search for said documentation on MSDN, use the search phrase
“FOO object model” where FOO is the name of the application.
If you’re trying to automate a nonMS application, then you’ll need to
check the documentation for the application.
If you didn’t know, you can only automate applications with OLE if
they expose an OLE interface. Those that don’t may support DDE
(Dynamic Data Exchange - Wikipedia).
So, I’m trying to figure out how to automate various programs using
ruby, and feeling a bit over my head at the moment. I’m still pretty
new to ruby and programming, so maybe this is beyond me, but its the #1
reason I decided to learn ruby in the first place.
What I’m wondering is…where to start? I believe I’m right in the fact
that I need to be using WIN32OLE, but beyond that I can’t seem to get
anywhere.
How do you determine what the exact name of the program is that you need
to pass as a parameter when creating a new WIN32OLE
object(‘WhatProgramNameHere.Application’)? How do you find what methods
can be used with that specific program? Am I even right in assuming I
should be using WIN32OLE? If someone would be so kind as to steer me in
the right direction with some tips or reading material I’d be eternally
grateful.
Thanks for reading,
Marc
In addition to Charles’ recommendations, you’ll find a lot regarding
Windows automation on my “Ruby on Windows” blog:
Thanks for the replies; very useful stuff. Maybe I’m blind, but I’ve
been crawling through the MSDN documentation for help with iexpress, and
I can’t seem to figure out what its object is called. The best I can
find is a list of what command line switches/options it supports
(IExpress Setup Options | Microsoft Learn).
I’ve tried just guessing a large variety of obvious names for it as
well, but that doesn’t seem to do anything but make me want to slam my
face against a rock. If I’m completely overlooking it, can someone
point it out for me?
I did find, thanks to David’s blog, that I can start it up without OLE
using system(‘iexpress’) but I haven’t yet been able to succesfully make
use of the defined command line options with that.
Not sure which way is best, but if anyone can help out with either/both
that’d be awesome.
Thanks for the replies; very useful stuff. Maybe I’m blind, but I’ve
been crawling through the MSDN documentation for help with iexpress, and
I can’t seem to figure out what its object is called. The best I can
find is a list of what command line switches/options it supports
(IExpress Setup Options | Microsoft Learn).
I suspect that it doesn’t expose and OLE interface. Many of
Microsoft’s applications don’t. Building such an interface is time
consuming and costly, and I doubt they’d bother for something like
that.
Googling didn’t turn up anything, so I suspect that you’re out of
luck.
Microsoft’s applications don’t. Building such an interface is time
consuming and costly, and I doubt they’d bother for something like
that.
Googling didn’t turn up anything, so I suspect that you’re out of
luck.
I also doubt iexpress has OLE interface. Anyway if you are interested
in using Ruby for automation on Windows you can read my article about
MS Office automation I recently had to deal with on http://pragmaticdevnotes.wordpress.com/2008/12/17/with-a-little-help-from-ruby/.
Unfortunately I forgot to list some tools that can be useful for such
a tasks and the main one is:
With it you can browse all OLE objects registered on your system, see
their methods, properties and some other things. You should start it
and check whether iexpress has registered some OLE interfaces at all.
Besides you can examine code and see how you can get information about
OLE methods and their arguments, OLE properties, etc.
I did find, thanks to David’s blog, that I can start it up without OLE
using system(‘iexpress’) but I haven’t yet been able to succesfully make
use of the defined command line options with that.
Kernel#system works the same on windows and unix. Command line options
are given after the name of the program you want to run, separated by
a space. So, to start iexpress in quiet mode, try system(‘iexpress
/Q’). Alternately, you can pass each option in a separate string:
system(‘iexpress’,‘/Q’,‘/R:A’) starts it in quiet mode and forces a
restart when iexpress exits.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.