9

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?

Kevdog777
  • 447
Keltari
  • 75,447

7 Answers7

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
  • 51
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.

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.

Gareth
  • 19,080
JeffRSon
  • 312
1

On Windows 64-bit the 32-bit explorer.exe does not start the user shell.

  • c:\windows\explorer.exe is the 64-bit version.
  • For 64-bit programs c:\windows\syswow64\explorer.exe is the 32-bit version.
  • For 32-bit programs c:\windows\system32\explorer.exe is the 32-bit version and c:\windows\system32 is used before c:\windows.

When explorer.exe is not running as user shell:

  • calling explorer.exe from 32-bit program starts an explorer window.
  • calling explorer.exe from 64-bit program starts the explorer as user shell.
  • calling c:\windows\explorer.exe starts the explorer as user shell.

Tested on Windows 10.

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

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
  • 131
-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).