# win32ole.AppActivate broken in VISTA?

**URL:** <https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212>\
**Category:** Ruby\
**Created:** [January 26, 2008, 8:49am UTC](https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212 "2008-01-26T08:49:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Batzinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Robert\_Batzinger](https://www.ruby-forum.com/u/Robert_Batzinger)\
**Post date:** [January 26, 2008, 8:49am UTC](https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212/1 "2008-01-26T08:49:51Z")

</div>

I have been trying to use the win32ole module on Vista. However, the  
AppActivate method always fails regardless of whether simple or  
root-relative address are used in the following program. The module  
appears to be working well on all other versions of Windows. Does  
anyone know the fix to this?

require ‘win32ole’  
wsh = WIN32OLE.new(‘Wscript.Shell’)  
if wsh.AppActivate(‘notepad’)  
print ‘Success’  
else  
print ‘Fail’  
end

BTW Just typing the word notepad works at the DOS prompt and the  
WIN32OLE does open the OLE object

================  
Bob Batzinger  
Arkfriends  
South Bend, Indiana

---

<div class="post-metadata">

**Author:** ![Robert\_Batzinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Robert\_Batzinger](https://www.ruby-forum.com/u/Robert_Batzinger)\
**Post date:** [January 27, 2008, 3:45am UTC](https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212/2 "2008-01-27T03:45:41Z")

</div>

Robert Batzinger wrote:

> I have been trying to use the win32ole module on Vista. However, the  
> AppActivate method always fails regardless of whether simple or  
> root-relative address are used in the following program. The module  
> appears to be working well on all other versions of Windows. Does  
> anyone know the fix to this?
> 
> require ‘win32ole’  
> wsh = WIN32OLE.new(‘Wscript.Shell’)  
> if wsh.AppActivate(‘notepad’)  
> print ‘Success’  
> else  
> print ‘Fail’  
> end
> 
> BTW Just typing the word notepad works at the DOS prompt and the  
> WIN32OLE does open the OLE object
> 
> ================  
> Bob Batzinger  
> Arkfriends  
> South Bend, Indiana

Bob-

For what it’s worth, your code works for me using Ruby 1.8.6 on Windows  
Vista Home Premium.

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![Robert\_Batzinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Robert\_Batzinger](https://www.ruby-forum.com/u/Robert_Batzinger)\
**Post date:** [January 27, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212/3 "2008-01-27T14:10:17Z")

</div>

i’m on vista ultimate, and when notepad’s allready on, it switches to  
the  
notepad screen and prints “succes”  
but when notepad’s not activated, i get a “fail” as well.

2008/1/27, David M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Robert\_Batzinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Robert\_Batzinger](https://www.ruby-forum.com/u/Robert_Batzinger)\
**Post date:** [January 27, 2008, 4:31pm UTC](https://www.ruby-forum.com/t/win32ole-appactivate-broken-in-vista/127212/4 "2008-01-27T16:31:48Z")

</div>

On Jan 27, 2008 2:09 PM, Dirk M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > root-relative address are used in the following program. The module
> > > 
> > > BTW Just typing the word notepad works at the DOS prompt and the  
> > > WIN32OLE does open the OLE object

[AppActivate Method | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/wzcddbek(VS.85).aspx) says  
AppActivate searches by window title. That means the app must be  
already running.  
You might want to use the Run method instead (if you want to start a  
new instance of notepad).

Other than that, you may try

1. checking whether the window title really contains the specified  
string
2. running the script from another language (.vbs, .wsh, vba, python)

(I’m not an expert on wsh, so please take these as hints only)

J.
