3 * Copyright (C) 2001, 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Userinit Logon Application
22 * FILE: base/system/userinit/userinit.c
23 * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
24 * Hervé Poussineau (hpoussin@reactos.org)
29 #define CMP_MAGIC 0x01234567
31 /* GLOBALS ******************************************************************/
36 /* FUNCTIONS ****************************************************************/
49 TRACE("(%p, %s, %p)\n", hKey
, debugstr_w(pszKey
), pValue
);
51 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
52 if (rc
!= ERROR_SUCCESS
)
54 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey
), rc
);
59 WARN("Wrong registry data type (%u vs %u)\n", dwType
, REG_SZ
);
60 return ERROR_FILE_NOT_FOUND
;
62 Value
= (WCHAR
*) HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
66 return ERROR_NOT_ENOUGH_MEMORY
;
68 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)Value
, &cbData
);
69 if (rc
!= ERROR_SUCCESS
)
71 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey
), rc
);
72 HeapFree(GetProcessHeap(), 0, Value
);
75 /* NULL-terminate the string */
76 Value
[cbData
/ sizeof(WCHAR
)] = L
'\0';
85 HKEY ControlKey
= NULL
;
86 LPWSTR SystemStartOptions
= NULL
;
87 LPWSTR CurrentOption
, NextOption
; /* Pointers into SystemStartOptions */
95 REGSTR_PATH_CURRENT_CONTROL_SET
,
99 if (rc
!= ERROR_SUCCESS
)
101 WARN("RegOpenKeyEx() failed with error %lu\n", rc
);
105 rc
= ReadRegSzKey(ControlKey
, L
"SystemStartOptions", &SystemStartOptions
);
106 if (rc
!= ERROR_SUCCESS
)
108 WARN("ReadRegSzKey() failed with error %lu\n", rc
);
112 /* Check for CONSOLE switch in SystemStartOptions */
113 CurrentOption
= SystemStartOptions
;
114 while (CurrentOption
)
116 NextOption
= wcschr(CurrentOption
, L
' ');
119 if (_wcsicmp(CurrentOption
, L
"CONSOLE") == 0)
121 TRACE("Found 'CONSOLE' boot option\n");
125 CurrentOption
= NextOption
? NextOption
+ 1 : NULL
;
129 if (ControlKey
!= NULL
)
130 RegCloseKey(ControlKey
);
131 HeapFree(GetProcessHeap(), 0, SystemStartOptions
);
132 TRACE("IsConsoleShell() returning %d\n", ret
);
138 OUT WCHAR
*CommandLine
, /* must be at least MAX_PATH long */
143 WCHAR Shell
[MAX_PATH
];
144 BOOL ConsoleShell
= IsConsoleShell();
147 TRACE("(%p, %p)\n", CommandLine
, hRootKey
);
149 rc
= RegOpenKeyExW(hRootKey
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
150 0, KEY_QUERY_VALUE
, &hKey
);
151 if (rc
!= ERROR_SUCCESS
)
153 WARN("RegOpenKeyEx() failed with error %lu\n", rc
);
157 Size
= sizeof(Shell
);
158 rc
= RegQueryValueExW(hKey
,
159 ConsoleShell
? L
"ConsoleShell" : L
"Shell",
166 if (rc
!= ERROR_SUCCESS
)
168 WARN("RegQueryValueEx() failed with error %lu\n", rc
);
172 if ((Type
== REG_SZ
) || (Type
== REG_EXPAND_SZ
))
174 TRACE("Found command line %s\n", debugstr_w(Shell
));
175 wcscpy(CommandLine
, Shell
);
180 WARN("Wrong type %lu (expected %u or %u)\n", Type
, REG_SZ
, REG_EXPAND_SZ
);
186 StartAutoApplications(
189 WCHAR szPath
[MAX_PATH
] = {0};
192 WIN32_FIND_DATAW findData
;
193 SHELLEXECUTEINFOW ExecInfo
;
196 TRACE("(%d)\n", clsid
);
198 hResult
= SHGetFolderPathW(NULL
, clsid
, NULL
, SHGFP_TYPE_CURRENT
, szPath
);
199 len
= wcslen(szPath
);
200 if (!SUCCEEDED(hResult
) || len
== 0)
202 WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
206 wcscat(szPath
, L
"\\*");
207 hFind
= FindFirstFileW(szPath
, &findData
);
208 if (hFind
== INVALID_HANDLE_VALUE
)
210 WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath
), GetLastError());
216 if (!(findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) && (findData
.nFileSizeHigh
|| findData
.nFileSizeLow
))
218 ZeroMemory(&ExecInfo
, sizeof(ExecInfo
));
219 ExecInfo
.cbSize
= sizeof(ExecInfo
);
220 wcscpy(&szPath
[len
+1], findData
.cFileName
);
221 ExecInfo
.lpVerb
= L
"open";
222 ExecInfo
.lpFile
= szPath
;
223 ExecInfo
.lpDirectory
= NULL
;
224 TRACE("Executing %s in directory %s\n",
225 debugstr_w(findData
.cFileName
), debugstr_w(szPath
));
226 ShellExecuteExW(&ExecInfo
);
228 } while (FindNextFileW(hFind
, &findData
));
237 PROCESS_INFORMATION pi
;
238 WCHAR ExpandedShell
[MAX_PATH
];
240 TRACE("(%s)\n", debugstr_w(Shell
));
242 ZeroMemory(&si
, sizeof(si
));
244 si
.dwFlags
= STARTF_USESHOWWINDOW
;
245 si
.wShowWindow
= SW_SHOWNORMAL
;
246 ZeroMemory(&pi
, sizeof(pi
));
248 ExpandEnvironmentStringsW(Shell
, ExpandedShell
, ARRAYSIZE(ExpandedShell
));
250 if (!CreateProcessW(NULL
,
255 NORMAL_PRIORITY_CLASS
,
261 WARN("CreateProcess() failed with error %lu\n", GetLastError());
265 StartAutoApplications(CSIDL_STARTUP
);
266 StartAutoApplications(CSIDL_COMMON_STARTUP
);
267 CloseHandle(pi
.hProcess
);
268 CloseHandle(pi
.hThread
);
275 WCHAR Shell
[MAX_PATH
];
276 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
284 /* Safe Mode shell run */
285 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
286 L
"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
287 0, KEY_QUERY_VALUE
, &hKey
);
288 if (rc
== ERROR_SUCCESS
)
290 Size
= sizeof(Value
);
291 rc
= RegQueryValueExW(hKey
, L
"UseAlternateShell", NULL
,
292 &Type
, (LPBYTE
)&Value
, &Size
);
295 if (rc
== ERROR_SUCCESS
)
297 if (Type
== REG_DWORD
)
301 /* Safe Mode Alternate Shell required */
302 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
303 L
"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
305 if (rc
== ERROR_SUCCESS
)
307 Size
= sizeof(Shell
);
308 rc
= RegQueryValueExW(hKey
, L
"AlternateShell", NULL
,
309 &Type
, (LPBYTE
)Shell
, &Size
);
312 if (rc
== ERROR_SUCCESS
)
314 if ((Type
== REG_SZ
) || (Type
== REG_EXPAND_SZ
))
316 TRACE("Key located - %s\n", debugstr_w(Shell
));
318 /* Try to run alternate shell */
319 if (TryToStartShell(Shell
))
321 TRACE("Alternate shell started (Safe Mode)\n");
327 WARN("Wrong type %lu (expected %u or %u)\n",
328 Type
, REG_SZ
, REG_EXPAND_SZ
);
333 WARN("Alternate shell in Safe Mode required but not specified.");
340 WARN("Wrong type %lu (expected %u)\n", Type
, REG_DWORD
);
345 /* Try to run shell in user key */
346 if (GetShell(Shell
, HKEY_CURRENT_USER
) && TryToStartShell(Shell
))
348 TRACE("Started shell from HKEY_CURRENT_USER\n");
352 /* Try to run shell in local machine key */
353 if (GetShell(Shell
, HKEY_LOCAL_MACHINE
) && TryToStartShell(Shell
))
355 TRACE("Started shell from HKEY_LOCAL_MACHINE\n");
359 /* Try default shell */
360 if (IsConsoleShell())
362 if (GetSystemDirectoryW(Shell
, ARRAYSIZE(Shell
) - 8))
363 wcscat(Shell
, L
"\\cmd.exe");
365 wcscpy(Shell
, L
"cmd.exe");
369 if (GetWindowsDirectoryW(Shell
, ARRAYSIZE(Shell
) - 13))
370 wcscat(Shell
, L
"\\explorer.exe");
372 wcscpy(Shell
, L
"explorer.exe");
375 if (!TryToStartShell(Shell
))
377 WARN("Failed to start default shell %s\n", debugstr_w(Shell
));
378 LoadString( GetModuleHandle(NULL
), IDS_SHELL_FAIL
, szMsg
, ARRAYSIZE(szMsg
));
379 MessageBox(NULL
, szMsg
, NULL
, MB_OK
);
385 const WCHAR g_RegColorNames
[][32] = {
386 L
"Scrollbar", /* 00 = COLOR_SCROLLBAR */
387 L
"Background", /* 01 = COLOR_DESKTOP */
388 L
"ActiveTitle", /* 02 = COLOR_ACTIVECAPTION */
389 L
"InactiveTitle", /* 03 = COLOR_INACTIVECAPTION */
390 L
"Menu", /* 04 = COLOR_MENU */
391 L
"Window", /* 05 = COLOR_WINDOW */
392 L
"WindowFrame", /* 06 = COLOR_WINDOWFRAME */
393 L
"MenuText", /* 07 = COLOR_MENUTEXT */
394 L
"WindowText", /* 08 = COLOR_WINDOWTEXT */
395 L
"TitleText", /* 09 = COLOR_CAPTIONTEXT */
396 L
"ActiveBorder", /* 10 = COLOR_ACTIVEBORDER */
397 L
"InactiveBorder", /* 11 = COLOR_INACTIVEBORDER */
398 L
"AppWorkSpace", /* 12 = COLOR_APPWORKSPACE */
399 L
"Hilight", /* 13 = COLOR_HIGHLIGHT */
400 L
"HilightText", /* 14 = COLOR_HIGHLIGHTTEXT */
401 L
"ButtonFace", /* 15 = COLOR_BTNFACE */
402 L
"ButtonShadow", /* 16 = COLOR_BTNSHADOW */
403 L
"GrayText", /* 17 = COLOR_GRAYTEXT */
404 L
"ButtonText", /* 18 = COLOR_BTNTEXT */
405 L
"InactiveTitleText", /* 19 = COLOR_INACTIVECAPTIONTEXT */
406 L
"ButtonHilight", /* 20 = COLOR_BTNHIGHLIGHT */
407 L
"ButtonDkShadow", /* 21 = COLOR_3DDKSHADOW */
408 L
"ButtonLight", /* 22 = COLOR_3DLIGHT */
409 L
"InfoText", /* 23 = COLOR_INFOTEXT */
410 L
"InfoWindow", /* 24 = COLOR_INFOBK */
411 L
"ButtonAlternateFace", /* 25 = COLOR_ALTERNATEBTNFACE */
412 L
"HotTrackingColor", /* 26 = COLOR_HOTLIGHT */
413 L
"GradientActiveTitle", /* 27 = COLOR_GRADIENTACTIVECAPTION */
414 L
"GradientInactiveTitle", /* 28 = COLOR_GRADIENTINACTIVECAPTION */
415 L
"MenuHilight", /* 29 = COLOR_MENUHILIGHT */
416 L
"MenuBar" /* 30 = COLOR_MENUBAR */
425 TRACE("(%s)\n", debugstr_w(lpszCol
));
427 rgb
[0] = (BYTE
)wcstoul(lpszCol
, &lpszCol
, 10);
428 rgb
[1] = (BYTE
)wcstoul(lpszCol
, &lpszCol
, 10);
429 rgb
[2] = (BYTE
)wcstoul(lpszCol
, &lpszCol
, 10);
430 return RGB(rgb
[0], rgb
[1], rgb
[2]);
434 SetUserSysColors(VOID
)
445 rc
= RegOpenKeyExW(HKEY_CURRENT_USER
, REGSTR_PATH_COLORS
,
446 0, KEY_QUERY_VALUE
, &hKey
);
447 if (rc
!= ERROR_SUCCESS
)
449 WARN("RegOpenKeyEx() failed with error %lu\n", rc
);
453 for (i
= 0; i
< ARRAYSIZE(g_RegColorNames
); i
++)
455 Size
= sizeof(szColor
);
456 rc
= RegQueryValueExW(hKey
, g_RegColorNames
[i
], NULL
, &Type
,
457 (LPBYTE
)szColor
, &Size
);
458 if (rc
== ERROR_SUCCESS
&& Type
== REG_SZ
)
460 crColor
= StrToColorref(szColor
);
461 SetSysColors(1, &i
, &crColor
);
465 WARN("RegQueryValueEx(%s) failed with error %lu\n",
466 debugstr_w(g_RegColorNames
[i
]), rc
);
474 SetUserWallpaper(VOID
)
478 WCHAR szWallpaper
[MAX_PATH
+ 1];
483 rc
= RegOpenKeyExW(HKEY_CURRENT_USER
, REGSTR_PATH_DESKTOP
,
484 0, KEY_QUERY_VALUE
, &hKey
);
485 if (rc
!= ERROR_SUCCESS
)
487 WARN("RegOpenKeyEx() failed with error %lu\n", rc
);
491 Size
= sizeof(szWallpaper
);
492 rc
= RegQueryValueExW(hKey
,
500 if (rc
== ERROR_SUCCESS
&& Type
== REG_SZ
)
502 ExpandEnvironmentStringsW(szWallpaper
, szWallpaper
, ARRAYSIZE(szWallpaper
));
503 TRACE("Using wallpaper %s\n", debugstr_w(szWallpaper
));
505 /* Load and change the wallpaper */
506 SystemParametersInfoW(SPI_SETDESKWALLPAPER
, 0, szWallpaper
, SPIF_SENDCHANGE
);
510 /* Remove the wallpaper */
511 TRACE("No wallpaper set in registry (error %lu)\n", rc
);
512 SystemParametersInfoW(SPI_SETDESKWALLPAPER
, 0, NULL
, SPIF_SENDCHANGE
);
517 SetUserSettings(VOID
)
521 UpdatePerUserSystemParameters(1, TRUE
);
526 typedef DWORD (WINAPI
*PCMP_REPORT_LOGON
)(DWORD
, DWORD
);
532 PCMP_REPORT_LOGON CMP_Report_LogOn
;
536 hModule
= LoadLibraryW(L
"setupapi.dll");
539 WARN("LoadLibrary() failed with error %lu\n", GetLastError());
543 CMP_Report_LogOn
= (PCMP_REPORT_LOGON
)GetProcAddress(hModule
, "CMP_Report_LogOn");
544 if (CMP_Report_LogOn
)
545 CMP_Report_LogOn(CMP_MAGIC
, GetCurrentProcessId());
547 WARN("GetProcAddress() failed\n");
549 FreeLibrary(hModule
);
555 WCHAR Shell
[MAX_PATH
];
556 WCHAR szMsg
[RC_STRING_MAX_SIZE
];
558 if (GetWindowsDirectoryW(Shell
, ARRAYSIZE(Shell
) - 12))
559 wcscat(Shell
, L
"\\reactos.exe");
561 wcscpy(Shell
, L
"reactos.exe");
563 if (!TryToStartShell(Shell
))
565 ERR("Failed to start the installer: %s\n", debugstr_w(Shell
));
566 LoadStringW(GetModuleHandle(NULL
), IDS_INSTALLER_FAIL
, szMsg
, ARRAYSIZE(szMsg
));
567 MessageBoxW(NULL
, szMsg
, NULL
, MB_OK
);
575 wWinMain(IN HINSTANCE hInst
,
576 IN HINSTANCE hPrevInstance
,
577 IN LPWSTR lpszCmdLine
,
588 State
.NextPage
= LOCALEPAGE
;
593 State
.NextPage
= DONE
;
597 if (State
.NextPage
!= DONE
)
602 if (State
.Run
== SHELL
)
607 else if (State
.Run
== INSTALLER
)