8

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
  • 2
  • 7
  • 31
Keltari
  • 71,875
  • 26
  • 179
  • 229
  • 2
    is 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 Sep 12 '13 at 16:45
  • 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 Sep 12 '13 at 17:04
  • 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](http://gpsearch.azurewebsites.net/#2496) (the site can be flaky in non IE browsers) instead of the registry key you are using. – Scott Chamberlain Sep 12 '13 at 17:41
  • 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 Sep 12 '13 at 19:28
  • 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 Sep 13 '13 at 03:11
  • 1
    I'd highly question the need to replace the entire Shell just to show a EULA. Global solution to a local problem. – surfasb Sep 14 '13 at 04:11
  • https://stackoverflow.com/a/18399877/4775650 - Working well for me – mt025 May 10 '18 at 15:07

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
  • 1
  • 1
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
  • 30,694
  • 7
  • 96
  • 109
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.

Gaff
  • 18,569
  • 15
  • 57
  • 68
JeffRSon
  • 302
  • 2
  • 12
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

clsturgeon
  • 196
  • 1
  • 1
  • 5
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
  • 111
  • 4
-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).

  • 1
    Please 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' Oct 12 '17 at 20:39