# Windows application automation

**URL:** <https://www.ruby-forum.com/t/windows-application-automation/57198>\
**Category:** Ruby\
**Created:** [April 7, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198 "2006-04-07T20:53:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolfgang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/54ee81/32.png) [@wolfgang](https://www.ruby-forum.com/u/wolfgang)\
**Post date:** [April 7, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198/1 "2006-04-07T20:53:58Z")

</div>

Hi all,

I wan’t to automate some applications which are running on mswin. Is it  
somehow possible to “send” key prints to that application? For example  
like “control s” for save.

Any suggestions?

Wolfgang

---

<div class="post-metadata">

**Author:** ![wolfgang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/54ee81/32.png) [@wolfgang](https://www.ruby-forum.com/u/wolfgang)\
**Post date:** [April 7, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198/2 "2006-04-07T21:00:09Z")

</div>

require ‘win32ole’ and read up on your favorite OLE browser.

What I’ve found is that I wind up fighting the (lack of) Ole  
documentation as much as anything.

Here’s a simple Ruby script I’ve written to check a mail store via  
Mapi for #of new messages and attachments:

require ‘win32ole’

mapiSession = WIN32OLE::new(‘Mapi.Session’)  
logonParam = “server” + “\n” + “account”  
mapiSession.Logon(‘ProfileInfo’ =\> logonParam)

new\_messages = 0  
total\_messages = 0

mapiSession.Inbox.Messages.each {  
|message|  
begin  
new\_messages += 1 if(message[‘UnRead’])  
total\_messages += 1  
puts message[‘Sender’].Address  
puts message[‘Subject’]  
puts 'Number of Attachments: ’ +  
message[‘Attachments’].count.to\_s  
end  
}

puts “You have #{new\_messages} new message(s)”  
puts “You have #{total\_messages} total message(s)”

mapiSession.Logoff

Was there a particular application(Outlook, Excel, etc?) that you were  
hoping to automate?

---

<div class="post-metadata">

**Author:** ![wolfgang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/54ee81/32.png) [@wolfgang](https://www.ruby-forum.com/u/wolfgang)\
**Post date:** [April 7, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198/3 "2006-04-07T21:15:19Z")

</div>

Hello Keith,

I have absolutely no information about OLE object that software uses. It  
is a software for a microtomograph and I need to save images every  
minute or so. All I would need is to send keyboard shortcuts to do the  
task.

Wolfgang

Keith S. schrieb:

---

<div class="post-metadata">

**Author:** ![wolfgang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/54ee81/32.png) [@wolfgang](https://www.ruby-forum.com/u/wolfgang)\
**Post date:** [April 7, 2006, 10:00pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198/4 "2006-04-07T22:00:52Z")

</div>

On 4/7/06, Wolfgang [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello Keith,
> 
> I have absolutely no information about OLE object that software uses. It  
> is a software for a microtomograph and I need to save images every  
> minute or so. All I would need is to send keyboard shortcuts to do the task.
> 
> Wolfgang

You can use the AutoItX com control to automate windows apps.

> **[AutoIt Scripting Language - AutoIt](https://www.autoitscript.com/site/autoit/)**
>
> AutoIt is a freeware BASIC-like scripting language designed for automating the Windows GUI and general purpose scripting.

Try searching the list for autoit, there have been recent posts about  
it and some have code samples.

---

<div class="post-metadata">

**Author:** ![wolfgang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/54ee81/32.png) [@wolfgang](https://www.ruby-forum.com/u/wolfgang)\
**Post date:** [April 7, 2006, 10:13pm UTC](https://www.ruby-forum.com/t/windows-application-automation/57198/5 "2006-04-07T22:13:15Z")

</div>

Hello Cristi,

that looks really good! Thanks a lot!  
Wolfgang

Cristi BALAN schrieb:
