[WINLOGON] When starting Setup (which runs with SYSTEM credentials), explicitly speci...
[reactos.git] / base / system / winlogon / setup.c
index 6927550..f5ef367 100644 (file)
@@ -10,8 +10,6 @@
 
 #include "winlogon.h"
 
-WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
-
 /* FUNCTIONS ****************************************************************/
 
 DWORD
@@ -56,7 +54,8 @@ GetSetupType(VOID)
 static
 DWORD
 WINAPI
-RunSetupThreadProc(IN LPVOID lpParameter)
+RunSetupThreadProc(
+    IN LPVOID lpParameter)
 {
     PROCESS_INFORMATION ProcessInformation;
     STARTUPINFOW StartupInfo;
@@ -81,7 +80,7 @@ RunSetupThreadProc(IN LPVOID lpParameter)
         return FALSE;
 
     /* Read key */
-    dwSize = (sizeof(Shell) / sizeof(Shell[0])) - 1;
+    dwSize = sizeof(Shell);
     dwError = RegQueryValueExW(hKey,
                                L"CmdLine",
                                NULL,
@@ -97,7 +96,7 @@ RunSetupThreadProc(IN LPVOID lpParameter)
 
     /* Expand string (if applicable) */
     if (dwType == REG_EXPAND_SZ)
-        ExpandEnvironmentStringsW(Shell, CommandLine, MAX_PATH);
+        ExpandEnvironmentStringsW(Shell, CommandLine, ARRAYSIZE(CommandLine));
     else if (dwType == REG_SZ)
         wcscpy(CommandLine, Shell);
     else
@@ -105,10 +104,12 @@ RunSetupThreadProc(IN LPVOID lpParameter)
 
     TRACE("Should run '%s' now\n", debugstr_w(CommandLine));
 
+    SwitchDesktop(WLSession->ApplicationDesktop);
+
     /* Start process */
     StartupInfo.cb = sizeof(StartupInfo);
     StartupInfo.lpReserved = NULL;
-    StartupInfo.lpDesktop = NULL;
+    StartupInfo.lpDesktop = L"WinSta0\\Default";
     StartupInfo.lpTitle = NULL;
     StartupInfo.dwFlags = 0;
     StartupInfo.cbReserved2 = 0;
@@ -127,6 +128,7 @@ RunSetupThreadProc(IN LPVOID lpParameter)
     if (!Result)
     {
         TRACE("Failed to run setup process\n");
+        SwitchDesktop(WLSession->WinlogonDesktop);
         return FALSE;
     }
 
@@ -139,6 +141,8 @@ RunSetupThreadProc(IN LPVOID lpParameter)
     CloseHandle(ProcessInformation.hThread);
     CloseHandle(ProcessInformation.hProcess);
 
+    SwitchDesktop(WLSession->WinlogonDesktop);
+
     TRACE ("RunSetup() done\n");
 
     return TRUE;
@@ -156,6 +160,8 @@ RunSetup(VOID)
                            NULL,
                            0,
                            NULL);
+    if (hThread != NULL)
+        CloseHandle(hThread);
 
     return hThread != NULL;
 }