mdog has asked for the wisdom of the Perl Monks concerning the following question:

Brethern --

How does one go about taking control of a program that is running on Windows?

Basically, I want to take control a program and tell it to exit properly (because if it exits on its own, it saves a bunch of data automatically. If I just kill the PID, then nothing gets saved).

After figuring out the classname from spy.exe, I am able to do this:

use Win32::GUI; $smartboardHandle = Win32::GUI::FindWindow("TMainform", "");

to get a handle for the program and I know the next step would be to issue SendMessage commands but since I don't know the API of the program, I think I am SOL (unless there is a standard message that says "Hey, why don't you close").

I have tried Win32::Process but invariably, I all I can do is kill the PID and that doesn't get the "Save and Close" I am looking for.

So any Windoze hackers have any clues for me?

Thanks,
Mdog

Replies are listed 'Best First'.
Re: Controlling a program in Windows
by Thelonius (Priest) on Jan 27, 2003 at 18:37 UTC
    See this discussion. The messages WM_QUERYENDSESSION and WM_ENDSESSION look like what you need.
Re: Controlling a program in Windows
by ibanix (Hermit) on Jan 27, 2003 at 19:19 UTC
    Have you looked at Win32::CtrlGUI?

    Cheers,
    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
Re: Controlling a program in Windows
by Mr. Muskrat (Canon) on Jan 27, 2003 at 18:18 UTC

    Without knowing what program it is (and whether of not it likes getting told what to do ;), I'd say that you should send the proper keystrokes to make it "Save and Close".

    Win32::GuiTest is real easy to use for this...
    See Re: Re: TWAIN Issues and Perl for an example of it's usage.

Re: Controlling a program in Windows
by mdog (Pilgrim) on Jan 27, 2003 at 19:22 UTC
    Awesome!

    Thanks for the advice!