Waiting for an .exe to execute

Dec 16, 2011 at 8:59pm
I'm almost finished with this project, and this forum as been invaluable, but I have what I hope is one final problem before I put the final program together.

I'm trying to open an .exe file (S:\storm.exe) and then, once it's fully open, do some keystrokes. The program will automatically read from some .xls files and input the information (again, via keystrokes) into storm.

My problem is this: I need to have storm full open (which takes between 1-5 seconds) before continuing any of the code. system(); is what I used first but obviously that wouldn't work so I learned how to use ShellExecute, but shell execute required a Sleep(); afterwards to wait till it opened.

This was kinda sloppy (to me at least) so I'm trying to find another way. I tried createprocess followed by a WaitForSingleObject but that waits until storm.exe is closed before continuing (much like system(); did.)

Any recommendations?
Dec 16, 2011 at 9:11pm
I can't really understand what you are talking about but maybe you could use a flag?

1
2
3
4
5
6
7
8
9
10
11
12
13
main( )
{
    bool bReady = false;

    while( !bReady )
    {
        bReady = IsReady( );
    }


    // start your program/code or whatever

}


does that apply at all to what you're talking about?
Dec 16, 2011 at 10:26pm
What you really want is WaitForInputIdle() API if you plan to send keystrokes with SendInput after.
Dec 16, 2011 at 10:27pm
closed account (DSLq5Di1)
http://msdn.microsoft.com/en-us/library/ms687022%28VS.85%29.aspx
Dec 16, 2011 at 11:14pm
IIRC, createprocess() returns after the target process is created -- and returns information in the processinfo struct you pass to it.

Hope this helps.
Topic archived. No new replies allowed.