views:

553

answers:

4

I need to make sure that explorer.exe runs as a system shell. What I need to do is:

  • Overwrite the current shell (Winlogon\Shell) with explorer.exe
  • Run explorer.exe (as shell)
  • Overwrite the current shell with my own shell.

Between the last two steps is a race:

  • If I overwrite the current shell with my own shell too quickly, only "My Documents" window opens.

So the question is, are there any events/mutexes/callbacks I can call to make sure that explorer is initialized as shell?

The best I managed to do is to wait for the tray window like:

while(!FindWindow("Shell_TrayWnd", NULL)) { 
     sleep(250);
}

Which seems kinda sloppy, is there a better way?

A: 

Why don't you watch the processes which are running? Prior to step 1 explorer.exe should not be listed as it is not the default shell. Step 2 you start it and watch for the process, which once available you then change.

I am not sure if you are on the .NET framework or not but if you are the events on the StartInfo classes should be enough for your needs.

Robert MacLean
This wouldn't work. The process is listed as soon as it's spawned. The time between the process spawn and explorer being ready is kind of long(not to mention completely random).
arul
+4  A: 

I would not even try to do this. You should create a new winsta0 desktop (Win32 API CreateDesktop), start your Kiosk application on that desktop and switch to it. That way you leave the default desktop alone, running explorer, and can get back to it if you need to. We had much success doing this in a kiosk project we built.

ScottTx
I'm afraid this wouldn't work either, at some point I need the app to remain accessible even after the explorer is running.
arul
Build into your app the abiltiy to switch between running desktops using SwitchDesktop.
ScottTx
I mean that I need to display a status window of my app on the "main window".
arul
A: 

You haven't explained why you need 3 steps, "kiosk software" is not an explanation.

Have you tried simply setting the shell in system.ini like litestep and other desktop replacement software? If you have to switch back and forth then consider a shell switcher like ShellOn or LiteSpawn which were written for this task.

SpliFF
System.ini doesn't work, it's an old way from W95 times. I also don't need a third party solution, the one I posted in the original post works fine, I just thought that there might be a better way...
arul
+1  A: 

A better way (as in actually documented) would be to create a top-level window and wait for the "TaskbarCreated" broadcast. That way you also get rid of the Sleep() call.

The broadcast is documented here.

ilmcuts