[EXPLORER] Check registry key for default shell (#7502)

Improves detection of Explorer being the default shell.

- Check the "Software\Microsoft\Windows NT\CurrentVersion\Winlogon" key to see if Explorer is the default shell.
- Use this check to determine whether to start the desktop and taskbar or only open a file browser window.

JIRA issue CORE-19887
This commit is contained in:
Brady McDermott 2024-11-30 10:17:54 -07:00 committed by GitHub
parent 741535dc28
commit df197bc424
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,6 +87,47 @@ HideMinimizedWindows(IN BOOL bHide)
}
#endif
static BOOL
IsExplorerSystemShell()
{
BOOL bIsSystemShell = TRUE; // Assume we are the system shell by default.
WCHAR szPath[MAX_PATH];
if (!GetModuleFileNameW(NULL, szPath, _countof(szPath)))
return FALSE;
LPWSTR szExplorer = PathFindFileNameW(szPath);
HKEY hKeyWinlogon;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
0, KEY_READ, &hKeyWinlogon) != ERROR_SUCCESS)
{
// No registry access.
bIsSystemShell = TRUE;
}
else
{
LSTATUS Status;
DWORD dwType;
WCHAR szShell[MAX_PATH];
DWORD cbShell = sizeof(szShell);
// TODO: Add support for paths longer than MAX_PATH
Status = RegQueryValueExW(hKeyWinlogon, L"Shell", 0, &dwType, (LPBYTE)szShell, &cbShell);
if (Status == ERROR_SUCCESS)
{
if ((dwType == REG_SZ || dwType == REG_EXPAND_SZ) && StrStrI(szShell, szExplorer))
bIsSystemShell = TRUE;
else
bIsSystemShell = FALSE;
}
RegCloseKey(hKeyWinlogon);
}
return bIsSystemShell;
}
#if !WIN7_COMPAT_MODE
static INT
StartWithCommandLine(IN HINSTANCE hInstance)
@ -212,15 +253,14 @@ _tWinMain(IN HINSTANCE hInstance,
TRACE("Explorer starting... Command line: %S\n", lpCmdLine);
#if !WIN7_COMPAT_MODE
if (GetShellWindow() == NULL)
bExplorerIsShell = TRUE;
bExplorerIsShell = (GetShellWindow() == NULL) && IsExplorerSystemShell();
if (!bExplorerIsShell)
{
return StartWithCommandLine(hInstance);
}
#else
bExplorerIsShell = TRUE;
bExplorerIsShell = IsExplorerSystemShell();
#endif
return StartWithDesktop(hInstance);