ShellExecute and Win32OLE callback

Discussion in 'Ruby' started by Ryan Allan, May 29, 2008.

  1. Ryan Allan

    Ryan Allan Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Ryan Allan, May 29, 2008
    #1
    1. Advertising

  2. 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 ), 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Siep Korteling, May 29, 2008
    #2
    1. Advertising

  3. Ryan Allan

    Ryan Allan Guest

    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


    --
    Posted via http://www.ruby-forum.com/.
     
    Ryan Allan, May 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcel Sammut

    Using ShellExecute PrintTo

    Marcel Sammut, Jan 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,577
    Tony Edgecombe
    Jan 9, 2004
  2. Guest

    ShellExecute and Process

    Guest, Nov 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    572
  3. =?Utf-8?B?RGF2aWRT?=

    ShellExecute command for ASP.NET?

    =?Utf-8?B?RGF2aWRT?=, Sep 30, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    6,935
    Kevin Spencer
    Oct 1, 2004
  4. Masaki Suketa
    Replies:
    4
    Views:
    384
    Dave Burt
    Mar 27, 2006
  5. zxem
    Replies:
    1
    Views:
    237
Loading...

Share This Page