custom shell starts before all services loaded

  • Thread starter Thread starter Greg Brown
  • Start date Start date
G

Greg Brown

I found other posts similar to this on google, but no responses...

My custom shell starts, but no user input is available for several seconds.
I guess I could use EnumProcesses to wait until something starts, but not
sure what to wait for. The only thing I saw resembling a reply was a
suggestion that the startup app just wait 'a bit' until it started the
actual gui. I was hoping for something a little more deterministic.

Thanks,

Greg
 
I replied to your mail address, because my answer includes C++ code, so it's
a little OT, but then I thought that someone in the newsgroup could be
interested anyway, so here is my reply:



Hi Greg,
I use something similar to this to wait for my service to start:

SC_HANDLE s = OpenSCManager(NULL, NULL, GENERIC_READ);
if (s == NULL)
{
err = GetLastError();
}
SC_HANDLE sc_handle = OpenService(s, "name_of_the_service",

SERVICE_QUERY_STATUS);
if (sc_handle == NULL)
{
err = GetLastError();
CloseServiceHandle(s);
}
SERVICE_STATUS ss;
for (int count=0; count<50; count++)
{
if(!QueryServiceStatus(sc_handle, &ss))
{
err = GetLastError();
CloseServiceHandle(s);
CloseServiceHandle(sc_handle);
break;
}
if (ss.dwCurrentState == SERVICE_RUNNING)
{
// OK, now we can run our app!!!!
break;
}
Sleep(200);
}
CloseServiceHandle(s);
CloseServiceHandle(sc_handle);
if (ss.dwCurrentState != SERVICE_RUNNING)
{
// Timeout (50*200 = 10 seconds)
}

Sorry for the sintax, it's awful, but I'm in hurry.
It's not exactly what you need, and if you don't want to run the risk of
waiting forever with a while(1), you have to set a timeout, but you can
control this with a configuration file or something similar.

HTH

Marco
 
Greg,

I did not quite get what your requirement is. Do you just want to launch your shell app and know when user input is available in it?
Then you should look at WaitForInputIdle API. You may end up launching a very small app as your shell. The app will run your heavy
shell through CreateProcess and during the launching time it may show a splash screen. If you call to WaitForInputIdle with the
handle from CreateProcess, then you know for sure when user is able to do anything within the shell UI.
More detail, " ... the calling thread can use the WaitForInputIdle function to wait until the new process has finished its
initialization and is waiting for user input with no input pending. This can be useful for synchronization between parent and child
processes, because CreateProcess returns without waiting for the new process to finish its initialization. For example, the creating
process would use WaitForInputIdle before trying to find a window associated with the new process.".
 
Thanks for the replies. Let me try to reiterate my problem. I apologize if
this is wordy.

I have a 'basically' headless device. I say basically, because I _do_ have
a user interface, but it occurs on a custom hardware display, not on a vga
desktop, so it is headless in the sense that the user will never see the
window's desktop. For testing, I do have a standard vga monitor connected.

I created a small app for my custom shell which then starts my main app,
which is displayed on the custom display. Here's the bootup sequence. On
the vga monitor, I see the empty desktop come up, then the screen switches
to the 'loading person settings' screen, then my shell app apparently
starts, because my main app comes up on the custom display. At that point,
from the user's perspective, the system looks to be running, but he has no
input available yet (through standard keyboard interface). Back on the
desktop, the personal settings screen stays visible for what seems like an
eternity (not sure why this is so slow), and then finally my shell app
becomes visible on the desktop, and the keyboard input becomes available to
the user.

So, as you can see, my goal is to delay starting the main app until keyboard
input is available. Here's what I've tried so far:

I tried Slobodan's suggestion of using CMP_WaitNoPendingInstallEvents(), but
it did not work. I noticed that the 'HidServ' service was not running when
my shell initially started, so I tried Marco's suggestion of using
QueryServiceStatus() to wait for that service to be running, but that also
did not work. As far as WaitForInputIdle(), I understand that to mean that
I would be waiting until my main app _can_ accept input, not when input is
actually available from the system, maybe I'm wrong.

Perhaps my whole approach is misguided. Any other suggestions are welcome.

Thanks,

Greg


KM said:
Greg,

I did not quite get what your requirement is. Do you just want to launch
your shell app and know when user input is available in it?
Then you should look at WaitForInputIdle API. You may end up launching a
very small app as your shell. The app will run your heavy
shell through CreateProcess and during the launching time it may show a
splash screen. If you call to WaitForInputIdle with the
handle from CreateProcess, then you know for sure when user is able to do anything within the shell UI.
More detail, " ... the calling thread can use the WaitForInputIdle
function to wait until the new process has finished its
initialization and is waiting for user input with no input pending. This
can be useful for synchronization between parent and child
processes, because CreateProcess returns without waiting for the new
process to finish its initialization. For example, the creating
process would use WaitForInputIdle before trying to find a window
associated with the new process.".
 
Hi Greg,

Try something like:

for(x=0;x<20;x++)
{
Sleep(10);
CMP_WaitNoPendingInstallEvents(),
}

I know that it is not deterministic, but this is the easiest thing I can
think of without analyzing SDK.
Or you could track status of specific driver and/or service and when they
are activated then you could start your app.

Also you should ask how to solve this in some SDK/DDK news group.

Regards,
Slobodan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Have an opinion on the effectiveness of Microsoft Embedded newsgroups? Tell
Microsoft!
https://www.windowsembeddedeval.com/community/newsgroups
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Greg,

We have a similar application, where we needed to wait for the network to
be up and working. What we did was to do a simple VB Script that sleeps for
a period of time before it executes the applications. I then set the XPe
Shell to run the script file.

<clip>
set shell = createobject("WScript.Shell")
wscript.sleep 1000
shell.run "Myapp.exe"
<end Clip>
 
Back
Top