How to launch the Windows Explorer shell after starting with a different one?
The following is a hack, but for what I need it for its fine.
I created a C# program that shows some EULA text and has an Agree and Disagree button.
I set the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell
to launch that program.
When the computer boots, the normal login prompt shows.
After logging in, the custom EULA program launches.
There is no explorer shell, no start menu, no background, etc. (which is what I want).
The disagree button shuts down the pc and works fine.
I want the Agree button to load the normal windows explorer shell (start menu, background, etc).
I used the following C# command: Process.Start("explorer.exe");
However this launches an explorer window, not the shell. I want the shell to launch.
What am I missing?
Solution 1:
In Windows10, to restart an Explorer Desktop you must set Shell registry key to "explorer.exe" and kill the process "sihost.exe" or restart a new "sihost.exe" process.
Solution 2:
I do the exact same thing as you are doing, here is how I am launching Explorer
Process explorer = new Process();
explorer.StartInfo.FileName =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
if (explorer.Start() == false)
{
MessageBox.Show("Explorer failed to start.");
}
else
{
//(Snip) some other code that is not relevant.
explorer.WaitForExit();
}
//(Snip) some cleanup code I run after the user logs off.
and it works fine.
Now I am doing this inside a RDP session using this group policy (Computer Configuration\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Remote Session Environment\Start a program on connection
) not via the registry file you are using, so maybe that is why it works for me and not for you.
One other thing I may be doing different is I also call explorer.WaitForExit();
in my code and wait for explorer to close itself before closing my app.
Try using the way I start explorer and see if it works for you.
Solution 3:
Explorer must see some fulfilled conditions to launch as shell:
- Explorer must not run (which includes Control Panel, for instance)
- Explorer must see it is the actual shell - hence you need to replace that value before launching explorer.exe (could change it back a few seconds later)
- Sometimes it seems (on newer Windows versions) it depends on the process that launches explorer.exe - if it is "known" to explorer.exe -- I don't have any more details for this part though (and you couldn't change it, unfortunately)
Judging from your question you are at least missing part 2.