* Sync with recent trunk (r52637).
[reactos.git] / base / system / userinit / userinit.c
index 9eb9602..6dbf1bb 100644 (file)
@@ -212,7 +212,6 @@ StartAutoApplications(
         WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
         return;
     }
-    szPath[len] = L'\0';
 
     do
     {
@@ -220,9 +219,10 @@ StartAutoApplications(
         {
             memset(&ExecInfo, 0x0, sizeof(SHELLEXECUTEINFOW));
             ExecInfo.cbSize = sizeof(ExecInfo);
+            wcscpy(&szPath[len+1], findData.cFileName);
             ExecInfo.lpVerb = L"open";
-            ExecInfo.lpFile = findData.cFileName;
-            ExecInfo.lpDirectory = szPath;
+            ExecInfo.lpFile = szPath;
+            ExecInfo.lpDirectory = NULL;
             TRACE("Executing %s in directory %s\n",
                 debugstr_w(findData.cFileName), debugstr_w(szPath));
             ShellExecuteExW(&ExecInfo);
@@ -274,9 +274,70 @@ VOID StartShell(VOID)
 {
     WCHAR Shell[MAX_PATH];
     TCHAR szMsg[RC_STRING_MAX_SIZE];
+    DWORD Type, Size;
+    DWORD Value = 0;
+    LONG rc;
+    HKEY hKey;
 
     TRACE("()\n");
 
+    /* Safe Mode shell run */
+    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                       L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
+                       0, KEY_QUERY_VALUE, &hKey);
+    if(rc == ERROR_SUCCESS)
+    {
+        Size = sizeof(Value);
+        rc = RegQueryValueExW(hKey, L"UseAlternateShell", NULL,
+                              &Type, (LPBYTE)&Value, &Size);
+        if(rc == ERROR_SUCCESS)
+        {
+            RegCloseKey(hKey);
+            if(Type == REG_DWORD)
+            {
+                if(Value)
+                {
+                    /* Safe Mode Alternate Shell required */
+                    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                                       L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
+                                       0, KEY_READ, &hKey);
+                    if(rc == ERROR_SUCCESS)
+                    {
+                        Size = MAX_PATH * sizeof(WCHAR);
+                        rc = RegQueryValueExW(hKey, L"AlternateShell", NULL,
+                                              &Type, (LPBYTE)Shell, &Size);
+                        if(rc == ERROR_SUCCESS)
+                        {
+                            RegCloseKey(hKey);
+                            if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
+                            {
+                                TRACE("Key located - %s\n", debugstr_w(Shell));
+                                /* Try to run alternate shell */
+                                if (TryToStartShell(Shell))
+                                {
+                                    TRACE("Alternate shell started (Safe Mode)\n");
+                                    return;
+                                }
+                            }
+                            else
+                            {
+                                WARN("Wrong type %lu (expected %u or %u)\n",
+                                     Type, REG_SZ, REG_EXPAND_SZ);
+                            }
+                        }
+                        else
+                        {
+                            WARN("Alternate shell in Safe Mode required but not specified.");
+                        }
+                    }
+                }
+            }
+            else
+            {
+                WARN("Wrong type %lu (expected %u)\n", Type, REG_DWORD);
+            }
+        }
+    }
     /* Try to run shell in user key */
     if (GetShell(Shell, HKEY_CURRENT_USER) && TryToStartShell(Shell))
     {