ReactOS 0.4.16-dev-2207-geb15453
userinit.c File Reference
#include "userinit.h"
Include dependency graph for userinit.c:

Go to the source code of this file.

Macros

#define CMP_MAGIC   0x01234567
 

Typedefs

typedef DWORD(WINAPIPCMP_REPORT_LOGON) (DWORD, DWORD)
 

Functions

LONG ReadRegSzKey (IN HKEY hKey, IN LPCWSTR pszKey, OUT LPWSTR *pValue)
 
static BOOL IsConsoleShell (VOID)
 
static BOOL GetShell (OUT WCHAR *CommandLine, IN HKEY hRootKey)
 
static BOOL StartProcess (IN LPCWSTR CommandLine)
 
static BOOL StartShell (VOID)
 
static COLORREF StrToColorref (IN LPWSTR lpszCol)
 
static VOID SetUserSysColors (VOID)
 
static VOID SetUserWallpaper (VOID)
 
static VOID SetUserSettings (VOID)
 
static VOID NotifyLogon (VOID)
 
BOOL ExpandInstallerPath (IN LPCWSTR lpInstallerName, OUT LPWSTR lpInstallerPath, IN SIZE_T PathSize)
 
static BOOL StartInstaller (IN LPCWSTR lpInstallerName)
 
static BOOL EnablePrivilege (LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
 
int WINAPI wWinMain (IN HINSTANCE hInst, IN HINSTANCE hPrevInstance, IN LPWSTR lpszCmdLine, IN int nCmdShow)
 

Variables

HINSTANCE hInstance
 
const WCHAR g_RegColorNames [][32]
 

Macro Definition Documentation

◆ CMP_MAGIC

#define CMP_MAGIC   0x01234567

Definition at line 29 of file userinit.c.

Typedef Documentation

◆ PCMP_REPORT_LOGON

typedef DWORD(WINAPI * PCMP_REPORT_LOGON) (DWORD, DWORD)

Definition at line 459 of file userinit.c.

Function Documentation

◆ EnablePrivilege()

static BOOL EnablePrivilege ( LPCWSTR  lpszPrivilegeName,
BOOL  bEnablePrivilege 
)
static

Definition at line 629 of file userinit.c.

630{
632 HANDLE hToken;
634
637 &hToken);
638 if (!Success) return Success;
639
641 lpszPrivilegeName,
642 &tp.Privileges[0].Luid);
643 if (!Success) goto Quit;
644
645 tp.PrivilegeCount = 1;
646 tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0);
647
648 Success = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
649
650Quit:
651 CloseHandle(hToken);
652 return Success;
653}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:942
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

Referenced by wWinMain().

◆ ExpandInstallerPath()

BOOL ExpandInstallerPath ( IN LPCWSTR  lpInstallerName,
OUT LPWSTR  lpInstallerPath,
IN SIZE_T  PathSize 
)

Definition at line 488 of file userinit.c.

492{
493 SYSTEM_INFO SystemInfo;
494 SIZE_T cchInstallerNameLen;
495 PWSTR ptr;
496 DWORD dwAttribs;
497
498 cchInstallerNameLen = wcslen(lpInstallerName);
499 if (PathSize < cchInstallerNameLen)
500 {
501 /* The buffer is not large enough to contain the installer file name */
502 *lpInstallerPath = UNICODE_NULL;
503 return FALSE;
504 }
505
506 /*
507 * First, try to find the installer using the default drive, under
508 * the directory whose name corresponds to the currently-running
509 * CPU architecture.
510 */
511 GetSystemInfo(&SystemInfo);
512
513 *lpInstallerPath = UNICODE_NULL;
514 /* Alternatively one can use SharedUserData->NtSystemRoot */
515 GetSystemWindowsDirectoryW(lpInstallerPath, PathSize - cchInstallerNameLen - 1);
516 ptr = wcschr(lpInstallerPath, L'\\');
517 if (ptr)
518 *++ptr = UNICODE_NULL;
519 else
520 *lpInstallerPath = UNICODE_NULL;
521
522 /* Append the corresponding CPU architecture */
523 switch (SystemInfo.wProcessorArchitecture)
524 {
526 StringCchCatW(lpInstallerPath, PathSize, L"I386");
527 break;
528
530 StringCchCatW(lpInstallerPath, PathSize, L"MIPS");
531 break;
532
534 StringCchCatW(lpInstallerPath, PathSize, L"ALPHA");
535 break;
536
538 StringCchCatW(lpInstallerPath, PathSize, L"PPC");
539 break;
540
542 StringCchCatW(lpInstallerPath, PathSize, L"SHX");
543 break;
544
546 StringCchCatW(lpInstallerPath, PathSize, L"ARM");
547 break;
548
550 StringCchCatW(lpInstallerPath, PathSize, L"IA64");
551 break;
552
554 StringCchCatW(lpInstallerPath, PathSize, L"ALPHA64");
555 break;
556
558 StringCchCatW(lpInstallerPath, PathSize, L"AMD64");
559 break;
560
561 // case PROCESSOR_ARCHITECTURE_MSIL: /* .NET CPU-independent code */
563 default:
564 WARN("Unknown processor architecture %lu\n", SystemInfo.wProcessorArchitecture);
566 break;
567 }
568
570 StringCchCatW(lpInstallerPath, PathSize, L"\\");
571 StringCchCatW(lpInstallerPath, PathSize, lpInstallerName);
572
573 dwAttribs = GetFileAttributesW(lpInstallerPath);
574 if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
575 !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
576 {
577 /* We have found the installer */
578 return TRUE;
579 }
580
581 WARN("Couldn't find the installer '%s', trying alternative.\n", debugstr_w(lpInstallerPath));
582
583 /*
584 * We failed. Try to find the installer from either the current
585 * ReactOS installation directory, or from our current directory.
586 */
587 *lpInstallerPath = UNICODE_NULL;
588 /* Alternatively one can use SharedUserData->NtSystemRoot */
589 if (GetSystemWindowsDirectoryW(lpInstallerPath, PathSize - cchInstallerNameLen - 1))
590 StringCchCatW(lpInstallerPath, PathSize, L"\\");
591 StringCchCatW(lpInstallerPath, PathSize, lpInstallerName);
592
593 dwAttribs = GetFileAttributesW(lpInstallerPath);
594 if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
595 !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
596 {
597 /* We have found the installer */
598 return TRUE;
599 }
600
601 /* Installer not found */
602 ERR("Couldn't find the installer '%s'.\n", debugstr_w(lpInstallerPath));
603 *lpInstallerPath = UNICODE_NULL;
604 return FALSE;
605}
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
#define wcschr
Definition: compat.h:17
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
UINT WINAPI GetSystemWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2397
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
#define PROCESSOR_ARCHITECTURE_ALPHA64
Definition: ketypes.h:112
#define PROCESSOR_ARCHITECTURE_ALPHA
Definition: ketypes.h:107
#define PROCESSOR_ARCHITECTURE_ARM
Definition: ketypes.h:110
#define PROCESSOR_ARCHITECTURE_UNKNOWN
Definition: ketypes.h:115
#define PROCESSOR_ARCHITECTURE_SHX
Definition: ketypes.h:109
#define PROCESSOR_ARCHITECTURE_MIPS
Definition: ketypes.h:106
#define PROCESSOR_ARCHITECTURE_PPC
Definition: ketypes.h:108
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define UNICODE_NULL
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
WORD wProcessorArchitecture
Definition: winbase.h:894
uint16_t * PWSTR
Definition: typedefs.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by StartInstaller().

◆ GetShell()

static BOOL GetShell ( OUT WCHAR CommandLine,
IN HKEY  hRootKey 
)
static

Definition at line 133 of file userinit.c.

136{
137 HKEY hKey;
138 DWORD Type, Size;
140 BOOL ConsoleShell = IsConsoleShell();
141 LONG rc;
142
143 rc = RegOpenKeyExW(hRootKey, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
144 0, KEY_QUERY_VALUE, &hKey);
145 if (rc != ERROR_SUCCESS)
146 {
147 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
148 return FALSE;
149 }
150
151 Size = sizeof(Shell);
153 ConsoleShell ? L"ConsoleShell" : L"Shell",
154 NULL,
155 &Type,
156 (LPBYTE)Shell,
157 &Size);
159
160 if (rc != ERROR_SUCCESS)
161 {
162 WARN("RegQueryValueEx() failed with error %lu\n", rc);
163 return FALSE;
164 }
165
166 if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
167 {
168 TRACE("Found command line %s\n", debugstr_w(Shell));
169 wcscpy(CommandLine, Shell);
170 return TRUE;
171 }
172 else
173 {
174 WARN("Wrong type %lu (expected %u or %u)\n", Type, REG_SZ, REG_EXPAND_SZ);
175 return FALSE;
176 }
177}
Type
Definition: Type.h:7
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define MAX_PATH
Definition: compat.h:34
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
long LONG
Definition: pedump.c:60
wcscpy
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char * LPBYTE
Definition: typedefs.h:53
static BOOL IsConsoleShell(VOID)
Definition: userinit.c:80
static int Shell(const char **args)
Definition: vfdcmd.c:1020
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by StartShell().

◆ IsConsoleShell()

static BOOL IsConsoleShell ( VOID  )
static

Definition at line 80 of file userinit.c.

81{
82 HKEY ControlKey = NULL;
83 LPWSTR SystemStartOptions = NULL;
84 LPWSTR CurrentOption, NextOption; /* Pointers into SystemStartOptions */
85 LONG rc;
86 BOOL ret = FALSE;
87
88 rc = RegOpenKeyEx(
91 0,
93 &ControlKey);
94 if (rc != ERROR_SUCCESS)
95 {
96 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
97 goto cleanup;
98 }
99
100 rc = ReadRegSzKey(ControlKey, L"SystemStartOptions", &SystemStartOptions);
101 if (rc != ERROR_SUCCESS)
102 {
103 WARN("ReadRegSzKey() failed with error %lu\n", rc);
104 goto cleanup;
105 }
106
107 /* Check for CONSOLE switch in SystemStartOptions */
108 CurrentOption = SystemStartOptions;
109 while (CurrentOption)
110 {
111 NextOption = wcschr(CurrentOption, L' ');
112 if (NextOption)
113 *NextOption = L'\0';
114 if (_wcsicmp(CurrentOption, L"CONSOLE") == 0)
115 {
116 TRACE("Found 'CONSOLE' boot option\n");
117 ret = TRUE;
118 goto cleanup;
119 }
120 CurrentOption = NextOption ? NextOption + 1 : NULL;
121 }
122
123cleanup:
124 if (ControlKey != NULL)
125 RegCloseKey(ControlKey);
126 HeapFree(GetProcessHeap(), 0, SystemStartOptions);
127
128 TRACE("IsConsoleShell() returning %u\n", ret);
129 return ret;
130}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
static void cleanup(void)
Definition: main.c:1335
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
return ret
Definition: mutex.c:146
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
#define REGSTR_PATH_CURRENT_CONTROL_SET
Definition: regstr.h:564
LONG ReadRegSzKey(IN HKEY hKey, IN LPCWSTR pszKey, OUT LPWSTR *pValue)
Definition: userinit.c:38
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:527
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by GetShell(), and StartShell().

◆ NotifyLogon()

static VOID NotifyLogon ( VOID  )
static

Definition at line 462 of file userinit.c.

463{
466
467 hModule = LoadLibraryW(L"setupapi.dll");
468 if (!hModule)
469 {
470 WARN("LoadLibrary() failed with error %lu\n", GetLastError());
471 return;
472 }
473
477 else
478 WARN("GetProcAddress() failed\n");
479
481}
CONFIGRET WINAPI CMP_Report_LogOn(_In_ DWORD dwMagic, _In_ DWORD dwProcessId)
Definition: cfgmgr.c:739
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE hModule
Definition: netsh.c:17
DWORD(WINAPI * PCMP_REPORT_LOGON)(DWORD, DWORD)
Definition: userinit.c:459
#define CMP_MAGIC
Definition: userinit.c:29
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158

Referenced by wWinMain().

◆ ReadRegSzKey()

LONG ReadRegSzKey ( IN HKEY  hKey,
IN LPCWSTR  pszKey,
OUT LPWSTR pValue 
)

Definition at line 38 of file userinit.c.

42{
43 LONG rc;
44 DWORD dwType;
45 DWORD cbData = 0;
47
48 rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData);
49 if (rc != ERROR_SUCCESS)
50 {
51 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
52 return rc;
53 }
54 if (dwType != REG_SZ)
55 {
56 WARN("Wrong registry data type (%u vs %u)\n", dwType, REG_SZ);
58 }
59 Value = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
60 if (!Value)
61 {
62 WARN("No memory\n");
64 }
65 rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)Value, &cbData);
66 if (rc != ERROR_SUCCESS)
67 {
68 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
70 return rc;
71 }
72 /* NULL-terminate the string */
73 Value[cbData / sizeof(WCHAR)] = L'\0';
74
75 *pValue = Value;
76 return ERROR_SUCCESS;
77}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define HeapAlloc
Definition: compat.h:733
PWCHAR pValue
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by IsConsoleShell().

◆ SetUserSettings()

static VOID SetUserSettings ( VOID  )
static

Definition at line 452 of file userinit.c.

453{
457}
DWORD WINAPI UpdatePerUserSystemParameters(DWORD dw1, DWORD dw2)
static VOID SetUserWallpaper(VOID)
Definition: userinit.c:411
static VOID SetUserSysColors(VOID)
Definition: userinit.c:373

Referenced by wWinMain().

◆ SetUserSysColors()

static VOID SetUserSysColors ( VOID  )
static

Definition at line 373 of file userinit.c.

374{
375 HKEY hKey;
376 INT i;
377 WCHAR szColor[25];
378 DWORD Type, Size;
379 COLORREF crColor;
380 LONG rc;
381
383 0, KEY_QUERY_VALUE, &hKey);
384 if (rc != ERROR_SUCCESS)
385 {
386 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
387 return;
388 }
389
390 for (i = 0; i < ARRAYSIZE(g_RegColorNames); i++)
391 {
392 Size = sizeof(szColor);
394 (LPBYTE)szColor, &Size);
395 if (rc == ERROR_SUCCESS && Type == REG_SZ)
396 {
397 crColor = StrToColorref(szColor);
398 SetSysColors(1, &i, &crColor);
399 }
400 else
401 {
402 WARN("RegQueryValueEx(%s) failed with error %lu\n",
404 }
405 }
406
408}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define REGSTR_PATH_COLORS
Definition: regstr.h:662
int32_t INT
Definition: typedefs.h:58
const WCHAR g_RegColorNames[][32]
Definition: userinit.c:326
static COLORREF StrToColorref(IN LPWSTR lpszCol)
Definition: userinit.c:361
DWORD COLORREF
Definition: windef.h:100
#define HKEY_CURRENT_USER
Definition: winreg.h:11
BOOL WINAPI SetSysColors(_In_ int cElements, _In_reads_(cElements) CONST INT *lpaElements, _In_reads_(cElements) CONST COLORREF *lpaRgbValues)

Referenced by SetUserSettings().

◆ SetUserWallpaper()

static VOID SetUserWallpaper ( VOID  )
static

Definition at line 411 of file userinit.c.

412{
413 HKEY hKey;
414 DWORD Type, Size;
415 WCHAR szWallpaper[MAX_PATH + 1];
416 LONG rc;
417
419 0, KEY_QUERY_VALUE, &hKey);
420 if (rc != ERROR_SUCCESS)
421 {
422 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
423 return;
424 }
425
426 Size = sizeof(szWallpaper);
428 L"Wallpaper",
429 NULL,
430 &Type,
431 (LPBYTE)szWallpaper,
432 &Size);
434
435 if (rc == ERROR_SUCCESS && Type == REG_SZ)
436 {
437 ExpandEnvironmentStringsW(szWallpaper, szWallpaper, ARRAYSIZE(szWallpaper));
438 TRACE("Using wallpaper %s\n", debugstr_w(szWallpaper));
439
440 /* Load and change the wallpaper */
442 }
443 else
444 {
445 /* Remove the wallpaper */
446 TRACE("No wallpaper set in registry (error %lu)\n", rc);
448 }
449}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:520
#define REGSTR_PATH_DESKTOP
Definition: regstr.h:659
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1380
#define SPIF_SENDCHANGE
Definition: winuser.h:1600
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)

Referenced by SetUserSettings().

◆ StartInstaller()

static BOOL StartInstaller ( IN LPCWSTR  lpInstallerName)
static

Definition at line 608 of file userinit.c.

609{
610 WCHAR Installer[MAX_PATH];
612
613 if (ExpandInstallerPath(lpInstallerName, Installer, ARRAYSIZE(Installer)))
614 {
615 /* We have found the installer */
616 if (StartProcess(Installer))
617 return TRUE;
618 }
619
620 /* We failed. Display an error message and quit. */
621 ERR("Failed to start the installer '%s'.\n", debugstr_w(Installer));
623 MessageBoxW(NULL, szMsg, NULL, MB_OK);
624 return FALSE;
625}
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
#define IDS_INSTALLER_FAIL
Definition: resource.h:29
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
static BOOL StartProcess(IN LPCWSTR CommandLine)
Definition: userinit.c:180
BOOL ExpandInstallerPath(IN LPCWSTR lpInstallerName, OUT LPWSTR lpInstallerPath, IN SIZE_T PathSize)
Definition: userinit.c:488
#define GetModuleHandle
Definition: winbase.h:3576
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_OK
Definition: winuser.h:801

Referenced by wWinMain().

◆ StartProcess()

static BOOL StartProcess ( IN LPCWSTR  CommandLine)
static

Definition at line 180 of file userinit.c.

182{
185 WCHAR ExpandedCmdLine[MAX_PATH];
186
187 ExpandEnvironmentStringsW(CommandLine, ExpandedCmdLine, ARRAYSIZE(ExpandedCmdLine));
188
189 ZeroMemory(&si, sizeof(si));
190 si.cb = sizeof(si);
191 si.dwFlags = STARTF_USESHOWWINDOW;
192 si.wShowWindow = SW_SHOWNORMAL;
193 ZeroMemory(&pi, sizeof(pi));
194
195 if (!CreateProcessW(NULL,
196 ExpandedCmdLine,
197 NULL,
198 NULL,
199 FALSE,
201 NULL,
202 NULL,
203 &si,
204 &pi))
205 {
206 WARN("CreateProcessW() failed with error %lu\n", GetLastError());
207 return FALSE;
208 }
209
212 return TRUE;
213}
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4600
#define ZeroMemory
Definition: minwinbase.h:31
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:185
#define STARTF_USESHOWWINDOW
Definition: winbase.h:468
#define SW_SHOWNORMAL
Definition: winuser.h:781

Referenced by StartInstaller(), and StartShell().

◆ StartShell()

static BOOL StartShell ( VOID  )
static

Definition at line 216 of file userinit.c.

217{
220 DWORD Type, Size;
221 DWORD Value = 0;
222 LONG rc;
223 HKEY hKey;
224
225 /* Safe Mode shell run */
227 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
228 0, KEY_QUERY_VALUE, &hKey);
229 if (rc == ERROR_SUCCESS)
230 {
231 Size = sizeof(Value);
232 rc = RegQueryValueExW(hKey, L"UseAlternateShell", NULL,
233 &Type, (LPBYTE)&Value, &Size);
235
236 if (rc == ERROR_SUCCESS)
237 {
238 if (Type == REG_DWORD)
239 {
240 if (Value)
241 {
242 /* Safe Mode Alternate Shell required */
244 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
245 0, KEY_READ, &hKey);
246 if (rc == ERROR_SUCCESS)
247 {
248 Size = sizeof(Shell);
249 rc = RegQueryValueExW(hKey, L"AlternateShell", NULL,
250 &Type, (LPBYTE)Shell, &Size);
252
253 if (rc == ERROR_SUCCESS)
254 {
255 if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
256 {
257 TRACE("Key located - %s\n", debugstr_w(Shell));
258
259 /* Try to run alternate shell */
260 if (StartProcess(Shell))
261 {
262 TRACE("Alternate shell started (Safe Mode)\n");
263 return TRUE;
264 }
265 }
266 else
267 {
268 WARN("Wrong type %lu (expected %u or %u)\n",
270 }
271 }
272 else
273 {
274 WARN("Alternate shell in Safe Mode required but not specified.\n");
275 }
276 }
277 }
278 }
279 else
280 {
281 WARN("Wrong type %lu (expected %u)\n", Type, REG_DWORD);
282 }
283 }
284 }
285
286 /* Try to run shell in user key */
288 {
289 TRACE("Started shell from HKEY_CURRENT_USER\n");
290 return TRUE;
291 }
292
293 /* Try to run shell in local machine key */
295 {
296 TRACE("Started shell from HKEY_LOCAL_MACHINE\n");
297 return TRUE;
298 }
299
300 /* Try default shell */
301 if (IsConsoleShell())
302 {
306 StringCchCatW(Shell, ARRAYSIZE(Shell), L"cmd.exe");
307 }
308 else
309 {
313 StringCchCatW(Shell, ARRAYSIZE(Shell), L"explorer.exe");
314 }
315
316 if (!StartProcess(Shell))
317 {
318 WARN("Failed to start default shell '%s'\n", debugstr_w(Shell));
320 MessageBoxW(NULL, szMsg, NULL, MB_OK);
321 return FALSE;
322 }
323 return TRUE;
324}
#define IDS_SHELL_FAIL
Definition: resource.h:28
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
#define KEY_READ
Definition: nt_native.h:1026
#define REG_DWORD
Definition: sdbapi.c:615
static BOOL GetShell(OUT WCHAR *CommandLine, IN HKEY hRootKey)
Definition: userinit.c:133

Referenced by wWinMain().

◆ StrToColorref()

static COLORREF StrToColorref ( IN LPWSTR  lpszCol)
static

Definition at line 361 of file userinit.c.

363{
364 BYTE rgb[3];
365
366 rgb[0] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
367 rgb[1] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
368 rgb[2] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
369 return RGB(rgb[0], rgb[1], rgb[2]);
370}
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
#define RGB(r, g, b)
Definition: precomp.h:67
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3521
unsigned char BYTE
Definition: xxhash.c:193

Referenced by SetUserSysColors().

◆ wWinMain()

int WINAPI wWinMain ( IN HINSTANCE  hInst,
IN HINSTANCE  hPrevInstance,
IN LPWSTR  lpszCmdLine,
IN int  nCmdShow 
)

Definition at line 657 of file userinit.c.

661{
662 BOOL bIsLiveCD, Success = TRUE;
663 STATE State;
664
666
667 bIsLiveCD = IsLiveCD();
668
669Restart:
671
672 if (bIsLiveCD)
673 {
674 State.NextPage = LOCALEPAGE;
675 State.Run = SHELL;
676 }
677 else
678 {
679 State.NextPage = DONE;
680 State.Run = SHELL;
681 }
682
683 if (State.NextPage != DONE) // && bIsLiveCD
684 {
686 }
687
688 switch (State.Run)
689 {
690 case SHELL:
692 if (Success)
693 NotifyLogon();
694 break;
695
696 case INSTALLER:
697 Success = StartInstaller(L"reactos.exe");
698 break;
699
700 case REBOOT:
701 {
705 Success = TRUE;
706 break;
707 }
708
709 default:
710 Success = FALSE;
711 break;
712 }
713
714 /*
715 * In LiveCD mode, go back to the main menu if we failed
716 * to either start the shell or the installer.
717 */
718 if (bIsLiveCD && !Success)
719 goto Restart;
720
721 return 0;
722}
HINSTANCE hInst
Definition: dxdiag.c:13
BOOL IsLiveCD(VOID)
Definition: livecd.c:106
VOID RunLiveCD(PSTATE pState)
Definition: livecd.c:892
#define DONE
Definition: rnr20lib.h:14
@ Restart
Definition: sacdrv.h:269
Definition: userinit.h:57
static VOID SetUserSettings(VOID)
Definition: userinit.c:452
static BOOL EnablePrivilege(LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
Definition: userinit.c:629
HINSTANCE hInstance
Definition: userinit.c:33
static VOID NotifyLogon(VOID)
Definition: userinit.c:462
static BOOL StartInstaller(IN LPCWSTR lpInstallerName)
Definition: userinit.c:608
static BOOL StartShell(VOID)
Definition: userinit.c:216
@ REBOOT
Definition: userinit.h:44
@ INSTALLER
Definition: userinit.h:43
@ SHELL
Definition: userinit.h:42
@ LOCALEPAGE
Definition: userinit.h:35
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:423
#define EWX_REBOOT
Definition: winuser.h:646
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)

Variable Documentation

◆ g_RegColorNames

const WCHAR g_RegColorNames[][32]

Definition at line 326 of file userinit.c.

Referenced by SetUserSysColors().

◆ hInstance

HINSTANCE hInstance

Definition at line 33 of file userinit.c.

Referenced by wWinMain().