# ShellExecute and Win32OLE callback

**URL:** <https://www.ruby-forum.com/t/shellexecute-and-win32ole-callback/138990>\
**Category:** Ruby\
**Created:** [May 29, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/shellexecute-and-win32ole-callback/138990 "2008-05-29T19:48:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [May 29, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/shellexecute-and-win32ole-callback/138990/1 "2008-05-29T19:48:07Z")

</div>

Hi everybody,

I’m trying to add a callback to a ShellExecute call. (Or at least get  
some way to find out when it finishes running.) I’m not having any luck  
with WIN32OLE\_EVENT, and all the examples I can find use Internet  
Explorer or Excel.

The code:

shell=WIN32OLE.new(‘Shell.Application’)

shell.ShellExecute(file\_to\_use, arguments, directory, operation, show)  
#All of these arguments are defined earlier. This call does what I want.

callback=WIN32OLE\_EVENT.new(shell, “Quit”)  
callback.on\_event(“Quit”){|\*args| do\_something}  
#do\_something is defined earlier.

No matter what is in place of “Quit”, even nil, it says “interface not  
supported” and refuses to run. Any suggestions? (It doesn’t have to use  
the event class, I only need to know when the ShellExecute process  
ends.)

This application is limited to core Ruby, no gems.

Thank you very much,  
-Ryan

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [May 29, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/shellexecute-and-win32ole-callback/138990/2 "2008-05-29T23:44:17Z")

</div>

Ryan Allan wrote:

> Hi everybody,
> 
> I’m trying to add a callback to a ShellExecute call. (Or at least get  
> some way to find out when it finishes running.) I’m not having any luck  
> with WIN32OLE\_EVENT, and all the examples I can find use Internet  
> Explorer or Excel.
> 
> The code:
> 
> shell=WIN32OLE.new(‘Shell.Application’)
> 
> shell.ShellExecute(file\_to\_use, arguments, directory, operation, show)  
> #All of these arguments are defined earlier. This call does what I want.

(…)

> -Ryan

You need ShellExecuteEx (see  
[http://www.codeproject.com/KB/system/newbiespawn.aspx](http://www.codeproject.com/KB/system/newbiespawn.aspx) ), but win32ole  
doesn’t seem to support ShellExecuteEx.

This is what I use in such cases (winXP) :

system(‘start /w notepad’)

# waits until notepad exits

system(‘start calc’)

# does not wait

puts “calc should be running, bye.”

hth,

Siep

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [May 29, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/shellexecute-and-win32ole-callback/138990/3 "2008-05-29T23:58:49Z")

</div>

Thanks Siep;

This does almost exactly what I want:

> This is what I use in such cases (winXP) :
> 
> system(‘start /w notepad’)
> 
> # waits until notepad exits
> 
> system(‘start calc’)
> 
> # does not wait
> 
> puts “calc should be running, bye.”

However, it does have the problem for which I originally used  
ShellExecute;  
I can’t have the cmd.exe black window popping up with it. How can I keep  
it from showing on screen? (I’m running a background thread to another  
process, and stuff flashing on screen annoys the users.)

Thanks again!  
-Ryan
