Skip to content

Commit df197bc

Browse files
authored
[EXPLORER] Check registry key for default shell (reactos#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
1 parent 741535d commit df197bc

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

base/shell/explorer/explorer.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,47 @@ HideMinimizedWindows(IN BOOL bHide)
8787
}
8888
#endif
8989

90+
static BOOL
91+
IsExplorerSystemShell()
92+
{
93+
BOOL bIsSystemShell = TRUE; // Assume we are the system shell by default.
94+
WCHAR szPath[MAX_PATH];
95+
96+
if (!GetModuleFileNameW(NULL, szPath, _countof(szPath)))
97+
return FALSE;
98+
99+
LPWSTR szExplorer = PathFindFileNameW(szPath);
100+
101+
HKEY hKeyWinlogon;
102+
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
103+
0, KEY_READ, &hKeyWinlogon) != ERROR_SUCCESS)
104+
{
105+
// No registry access.
106+
bIsSystemShell = TRUE;
107+
}
108+
else
109+
{
110+
LSTATUS Status;
111+
DWORD dwType;
112+
WCHAR szShell[MAX_PATH];
113+
DWORD cbShell = sizeof(szShell);
114+
115+
// TODO: Add support for paths longer than MAX_PATH
116+
Status = RegQueryValueExW(hKeyWinlogon, L"Shell", 0, &dwType, (LPBYTE)szShell, &cbShell);
117+
if (Status == ERROR_SUCCESS)
118+
{
119+
if ((dwType == REG_SZ || dwType == REG_EXPAND_SZ) && StrStrI(szShell, szExplorer))
120+
bIsSystemShell = TRUE;
121+
else
122+
bIsSystemShell = FALSE;
123+
}
124+
125+
RegCloseKey(hKeyWinlogon);
126+
}
127+
128+
return bIsSystemShell;
129+
}
130+
90131
#if !WIN7_COMPAT_MODE
91132
static INT
92133
StartWithCommandLine(IN HINSTANCE hInstance)
@@ -212,15 +253,14 @@ _tWinMain(IN HINSTANCE hInstance,
212253
TRACE("Explorer starting... Command line: %S\n", lpCmdLine);
213254

214255
#if !WIN7_COMPAT_MODE
215-
if (GetShellWindow() == NULL)
216-
bExplorerIsShell = TRUE;
256+
bExplorerIsShell = (GetShellWindow() == NULL) && IsExplorerSystemShell();
217257

218258
if (!bExplorerIsShell)
219259
{
220260
return StartWithCommandLine(hInstance);
221261
}
222262
#else
223-
bExplorerIsShell = TRUE;
263+
bExplorerIsShell = IsExplorerSystemShell();
224264
#endif
225265

226266
return StartWithDesktop(hInstance);

0 commit comments

Comments
 (0)