https://git.reactos.org/?p=reactos.git;a=commitdiff;h=df197bc424f319585a1373ab6d4d033fb938fefb

commit df197bc424f319585a1373ab6d4d033fb938fefb
Author:     Brady McDermott <[email protected]>
AuthorDate: Sat Nov 30 10:17:54 2024 -0700
Commit:     GitHub <[email protected]>
CommitDate: Sat Nov 30 10:17:54 2024 -0700

    [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
---
 base/shell/explorer/explorer.cpp | 46 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/base/shell/explorer/explorer.cpp b/base/shell/explorer/explorer.cpp
index a88cf050eea..d51a32976cc 100644
--- a/base/shell/explorer/explorer.cpp
+++ b/base/shell/explorer/explorer.cpp
@@ -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);

Reply via email to