使用ShellExecuteEx启动外部应用程序,并等待它初始化 [英] Start external app with ShellExecuteEx and wait until it become initialized
问题描述
ShellExecuteEx
来运行它们。运行每个应用程序的顺序是非常重要的,因为它们依赖于彼此。例如: 开始(App1);
如果App1.IsRunning然后
开始(App2);
如果App2.IsRunning然后
开始(App3);
.........................
如果应用程序(N-1).IsRunning然后
开始(应用程序(N));
一切正常,但有一个可能的问题:
ShellExecuteEx
启动应用程序,几乎立即返回。当例如 App1
已正确启动但尚未完成某些内部任务,但尚未准备好使用时,可能会出现此问题。但是 ShellExecuteEx
已经开始 App2
,这取决于 App1
,而 App2
将无法正常启动,因为它需要完全初始化 App1
。
请注意,我不想等待 App(N-1)
完成,然后开始 AppN
。
我不知道这是否可以用ShellExecuteEx解决,我试图使用
SEInfo.fMask:= SEE_MASK_NOCLOSEPROCESS或SEE_MASK_NOASYNC;
但没有任何效果。
之后启动 AppN
应用程序我有一个处理过程。如果我假设应用程序在其主窗口创建之后被初始化(所有应用程序都有一个窗口),我可以以某种方式在其消息队列中挂钩,并等到 WM_CREATE
出现或可能 WM_ACTIVATE
?在这种消息的压制下,我的应用程序将知道它可以继续。
这只是一个想法。但是,我不知道如何把这样的钩子。所以,如果你可以帮助我,或者你有一个更好的主意,将是伟大的:)
此外,该解决方案必须在Windows XP及更高版本上工作。
感谢您的时间。
已编辑
@Cosmic Prund:我不明白你为什么删除你的答案?我可能尝试你的想法...
你可以通过调用 WaitForInputIdle()
在 ShellExecute()
返回的每个进程句柄上。
等待指定的进程完成处理其初始输入并等待用户输入,没有输入挂起,或直到超时间隔已过。
I have an application which needs to run several other applications in chain. I am running them via ShellExecuteEx
. The order of running each of the apps is very important cause they are dependant on each other. For example:
Start(App1);
If App1.IsRunning then
Start(App2);
If App2.IsRunning then
Start(App3);
.........................
If App(N-1).IsRunning then
Start(App(N));
Everything works fine but there is a one possible problem:
ShellExecuteEx
starts the application, and return almost immediately. The problem might arise when for example App1
has started properly but has not finished some internal tasks, it is not yet ready to use. But ShellExecuteEx
is already starting App2
which depends on the App1
, and App2
won't start properly because it needs fully initialized App1
.
Please note, that I don't want to wait for App(N-1)
to finish and then start AppN
.
I don't know if this is possible to solve with ShellExecuteEx, I've tried to use
SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_NOASYNC;
but without any effect.
After starting the AppN
application I have a handle to the process. If I assume that the application is initialized after its main window is created (all of Apps have a window), can I somehow put a hook on its message queue and wait until WM_CREATE
appears or maybe WM_ACTIVATE
? In pressence of such message my Application would know that it can move on.
It's just an idea. However, I don't know how to put such hook. So if you could help me in this or you have a better idea that would be great:)
Also, the solution must work on Windows XP and above.
Thanks for your time.
Edited
@Cosmic Prund: I don't understand why did you delete your answer? I might try your idea...
You can probably achieve what you need by calling WaitForInputIdle()
on each process handle returned by ShellExecute()
.
Waits until the specified process has finished processing its initial input and is waiting for user input with no input pending, or until the time-out interval has elapsed.
这篇关于使用ShellExecuteEx启动外部应用程序,并等待它初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!