How to launch the Windows Explorer shell after starting with a different one?

7

3

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?

Keltari

Posted 2013-09-12T16:41:28.463

Reputation: 57 019

https://stackoverflow.com/a/18399877/4775650 - Working well for me – mt025 – 2018-05-10T15:07:26.897

2is explorer.exe already running as the desktop process when you invoke it? if there is no instance of explorer running for the login, it will spawn the desktop process, but if it is already running, it will spawn an explorer window. in what context is your application running? I assume it is before login? if not, the netlogin process has probably already spawned your desktop process. – Frank Thomas – 2013-09-12T16:45:02.170

No, explorer.exe is not running when the custom shell is launched. It doesnt run till I click the agree button. I assume I need to start something other than explorer.exe... I dont know... – Keltari – 2013-09-12T17:04:44.820

Are you doing this for RDP connections or do you need to show your EULA for locally logged on users too? If RDP only try using this group policy (the site can be flaky in non IE browsers) instead of the registry key you are using.

– Scott Chamberlain – 2013-09-12T17:41:59.347

looking at this article, it doesnt look like this method will work... http://social.technet.microsoft.com/Forums/windows/en-US/51e7090e-f367-4d0a-b737-b2feacf9b5ae/how-to-start-windows-shell-explorerexe-when-custom-shell-is-configured

– Keltari – 2013-09-12T19:28:54.750

I was wasting to much time trying to do a shell replacement. I just ended up creating a non moveable window that launches at startup and cant be closed with an alt-f4. Good enough for what I need to do. I am still wondering if this is possible... but as my previous comment states, it doesnt look like it. – Keltari – 2013-09-13T03:11:31.500

1I'd highly question the need to replace the entire Shell just to show a EULA. Global solution to a local problem. – surfasb – 2013-09-14T04:11:44.063

Answers

5

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.

Jieff

Posted 2013-09-12T16:41:28.463

Reputation: 51

That's it, restarting sihost.exe did it for me. Thanks a lot! – cheesus says stop firing mods – 2018-07-24T07:13:23.070

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.

Scott Chamberlain

Posted 2013-09-12T16:41:28.463

Reputation: 28 923

I tried your code, but it just launches a file explorer window, not the shell – Keltari – 2013-09-12T19:27:23.523

@Keltari do you need to support local logins or will only showing the EULA for RDP users work for what you want to do? – Scott Chamberlain – 2013-09-12T22:34:29.513

2

Explorer must see some fulfilled conditions to launch as shell:

  1. Explorer must not run (which includes Control Panel, for instance)
  2. 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)
  3. 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.

JeffRSon

Posted 2013-09-12T16:41:28.463

Reputation: 143

0

What I experienced when I followed the instructions on how to install a custom Shell, by installing and using Microsoft's Shell Launcher, I would first see my custom shell appear (without the taskbar, etc), but then the moment I launched Windows Explorer it would display the taskbar. See: https://docs.microsoft.com/en-us/windows-hardware/customize/enterprise/shell-launcher

clsturgeon

Posted 2013-09-12T16:41:28.463

Reputation: 166

0

Based on the working answer of @Jieff, I created a batch script to escape the custom shell.

@echo OFF

echo|set /p="Escape (1/6) - Changing shell to explorer.exe .......................... "
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d "explorer.exe" /f > NUL 2>NUL
IF %ERRORLEVEL% == 0 ( ECHO OK! ) ELSE ( ECHO FAIL! )

echo|set /p="Escape (2/6) - Killing sihost.exe ...................................... " 
taskkill /F /IM sihost.exe > NUL 2>NUL
echo OK!

echo|set /p="Escape (3/6) - Waiting some time for sihost.exe to shutdown ............ " 
timeout /T 5 /nobreak > NUL 2>NUL
echo OK!

echo|set /p="Escape (4/6) - Restarting sihost.exe ................................... " 
start sihost.exe > NUL 2>NUL
echo OK!

echo|set /p="Escape (5/6) - Waiting some time for sihost.exe to start ............... " 
timeout /T 15 /nobreak > NUL 2>NUL
echo OK!

:: 6/6 could be a REG change back to the previous custom shell for the next system (re)start. The explorer shell will still be available.

Daniel

Posted 2013-09-12T16:41:28.463

Reputation: 101

-1

Modify registry,put explorer.exe to shell, start new explorer.exe process (you does not have any process explorer.exe running) and return shell to your shell (empty value if needs).

Andypadullos

Posted 2013-09-12T16:41:28.463

Reputation: 1

1Please rewrite this in clear English (i.e., multiple complete sentences with correct grammar).  Expand shorthand like ‘‘modify registry’’ to usable instructions. Do not respond in comments; [edit] your answer to make it clearer and more complete. – G-Man Says 'Reinstate Monica' – 2017-10-12T20:39:32.083