* Sync with recent trunk (r52637).
[reactos.git] / base / system / winlogon / screensaver.c
index 17423e5..ba3e8d0 100644 (file)
@@ -231,7 +231,7 @@ InitializeScreenSaver(
        if (ScreenSaverThread)
                CloseHandle(ScreenSaverThread);
        else
-               WARN("WL: Unable to start screen saver thread\n");
+               ERR("WL: Unable to start screen saver thread\n");
 
        return TRUE;
 }
@@ -240,7 +240,7 @@ VOID
 StartScreenSaver(
        IN PWLSESSION Session)
 {
-       HKEY hKey = NULL;
+       HKEY hKey = NULL, hCurrentUser = NULL;
        WCHAR szApplicationName[MAX_PATH];
        WCHAR szCommandLine[MAX_PATH + 3];
        DWORD bufferSize = sizeof(szApplicationName) - sizeof(WCHAR);
@@ -254,18 +254,30 @@ StartScreenSaver(
 
        if (!ImpersonateLoggedOnUser(Session->UserToken))
        {
-               ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
+               ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
+               goto cleanup;
+       }
+
+       rc = RegOpenCurrentUser(
+               KEY_READ,
+               &hCurrentUser);
+       if (rc != ERROR_SUCCESS)
+       {
+               ERR("WL: RegOpenCurrentUser Error!\n");
                goto cleanup;
        }
 
        rc = RegOpenKeyExW(
-               HKEY_CURRENT_USER,
+               hCurrentUser,
                L"Control Panel\\Desktop",
                0,
                KEY_QUERY_VALUE,
                &hKey);
        if (rc != ERROR_SUCCESS)
+       {
+               ERR("WL: RegOpenKeyEx Error!\n");
                goto cleanup;
+       }
 
        rc = RegQueryValueExW(
                hKey,
@@ -275,15 +287,24 @@ StartScreenSaver(
                (LPBYTE)szApplicationName,
                &bufferSize);
        if (rc != ERROR_SUCCESS || dwType != REG_SZ)
+       {
+               ERR("WL: RegQueryValueEx Error!\n");
                goto cleanup;
+       }
 
        if (bufferSize == 0)
+       {
+               ERR("WL: Buffer size is NULL!\n");
                goto cleanup;
+       }
 
        szApplicationName[bufferSize / sizeof(WCHAR)] = 0; /* Terminate the string */
 
        if (wcslen(szApplicationName) == 0)
+       {
+               ERR("WL: Application Name length is zero!\n");
                goto cleanup;
+       }
 
        wsprintfW(szCommandLine, L"%s /s", szApplicationName);
        TRACE("WL: Executing %S\n", szCommandLine);
@@ -291,6 +312,7 @@ StartScreenSaver(
        ZeroMemory(&StartupInfo, sizeof(STARTUPINFOW));
        ZeroMemory(&ProcessInformation, sizeof(PROCESS_INFORMATION));
        StartupInfo.cb = sizeof(STARTUPINFOW);
+       StartupInfo.dwFlags = STARTF_SCRNSAVER;
        /* FIXME: run the screen saver on the screen saver desktop */
        ret = CreateProcessW(
                szApplicationName,
@@ -305,7 +327,7 @@ StartScreenSaver(
                &ProcessInformation);
        if (!ret)
        {
-               WARN("WL: Unable to start %S, error %lu\n", szApplicationName, GetLastError());
+               ERR("WL: Unable to start %S, error %lu\n", szApplicationName, GetLastError());
                goto cleanup;
        }
        CloseHandle(ProcessInformation.hThread);
@@ -330,6 +352,8 @@ cleanup:
        RevertToSelf();
        if (hKey)
                RegCloseKey(hKey);
+       if (hCurrentUser)
+               RegCloseKey(hCurrentUser);
        if (!ret)
        {
                PostMessageW(Session->SASWindow, WLX_WM_SAS, WLX_SAS_TYPE_SCRNSVR_ACTIVITY, 0);