ReactOS 0.4.17-dev-357-ga8f14ff
userinit.c File Reference
#include "userinit.h"
#include <userenv.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_ PCWSTR CommandLine, _In_opt_ PVOID pEnvironment)
 
static BOOL StartShell (_In_opt_ PVOID pEnvironment)
 
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 30 of file userinit.c.

Typedef Documentation

◆ PCMP_REPORT_LOGON

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

Definition at line 472 of file userinit.c.

Function Documentation

◆ EnablePrivilege()

static BOOL EnablePrivilege ( LPCWSTR  lpszPrivilegeName,
BOOL  bEnablePrivilege 
)
static

Definition at line 642 of file userinit.c.

643{
645 HANDLE hToken;
647
650 &hToken);
651 if (!Success) return Success;
652
654 lpszPrivilegeName,
655 &tp.Privileges[0].Luid);
656 if (!Success) goto Quit;
657
658 tp.PrivilegeCount = 1;
659 tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0);
660
661 Success = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
662
663Quit:
664 CloseHandle(hToken);
665 return Success;
666}
#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 501 of file userinit.c.

505{
506 SYSTEM_INFO SystemInfo;
507 SIZE_T cchInstallerNameLen;
508 PWSTR ptr;
509 DWORD dwAttribs;
510
511 cchInstallerNameLen = wcslen(lpInstallerName);
512 if (PathSize < cchInstallerNameLen)
513 {
514 /* The buffer is not large enough to contain the installer file name */
515 *lpInstallerPath = UNICODE_NULL;
516 return FALSE;
517 }
518
519 /*
520 * First, try to find the installer using the default drive, under
521 * the directory whose name corresponds to the currently-running
522 * CPU architecture.
523 */
524 GetSystemInfo(&SystemInfo);
525
526 *lpInstallerPath = UNICODE_NULL;
527 /* Alternatively one can use SharedUserData->NtSystemRoot */
528 GetSystemWindowsDirectoryW(lpInstallerPath, PathSize - cchInstallerNameLen - 1);
529 ptr = wcschr(lpInstallerPath, L'\\');
530 if (ptr)
531 *++ptr = UNICODE_NULL;
532 else
533 *lpInstallerPath = UNICODE_NULL;
534
535 /* Append the corresponding CPU architecture */
536 switch (SystemInfo.wProcessorArchitecture)
537 {
539 StringCchCatW(lpInstallerPath, PathSize, L"I386");
540 break;
541
543 StringCchCatW(lpInstallerPath, PathSize, L"MIPS");
544 break;
545
547 StringCchCatW(lpInstallerPath, PathSize, L"ALPHA");
548 break;
549
551 StringCchCatW(lpInstallerPath, PathSize, L"PPC");
552 break;
553
555 StringCchCatW(lpInstallerPath, PathSize, L"SHX");
556 break;
557
559 StringCchCatW(lpInstallerPath, PathSize, L"ARM");
560 break;
561
563 StringCchCatW(lpInstallerPath, PathSize, L"IA64");
564 break;
565
567 StringCchCatW(lpInstallerPath, PathSize, L"ALPHA64");
568 break;
569
571 StringCchCatW(lpInstallerPath, PathSize, L"AMD64");
572 break;
573
574 // case PROCESSOR_ARCHITECTURE_MSIL: /* .NET CPU-independent code */
576 default:
577 WARN("Unknown processor architecture %lu\n", SystemInfo.wProcessorArchitecture);
579 break;
580 }
581
583 StringCchCatW(lpInstallerPath, PathSize, L"\\");
584 StringCchCatW(lpInstallerPath, PathSize, lpInstallerName);
585
586 dwAttribs = GetFileAttributesW(lpInstallerPath);
587 if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
588 !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
589 {
590 /* We have found the installer */
591 return TRUE;
592 }
593
594 WARN("Couldn't find the installer '%s', trying alternative.\n", debugstr_w(lpInstallerPath));
595
596 /*
597 * We failed. Try to find the installer from either the current
598 * ReactOS installation directory, or from our current directory.
599 */
600 *lpInstallerPath = UNICODE_NULL;
601 /* Alternatively one can use SharedUserData->NtSystemRoot */
602 if (GetSystemWindowsDirectoryW(lpInstallerPath, PathSize - cchInstallerNameLen - 1))
603 StringCchCatW(lpInstallerPath, PathSize, L"\\");
604 StringCchCatW(lpInstallerPath, PathSize, lpInstallerName);
605
606 dwAttribs = GetFileAttributesW(lpInstallerPath);
607 if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
608 !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
609 {
610 /* We have found the installer */
611 return TRUE;
612 }
613
614 /* Installer not found */
615 ERR("Couldn't find the installer '%s'\n", debugstr_w(lpInstallerPath));
616 *lpInstallerPath = UNICODE_NULL;
617 return FALSE;
618}
#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:636
UINT WINAPI GetSystemWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2316
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
#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 134 of file userinit.c.

137{
138 HKEY hKey;
139 DWORD Type, Size;
141 BOOL ConsoleShell = IsConsoleShell();
142 LONG rc;
143
144 rc = RegOpenKeyExW(hRootKey, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
145 0, KEY_QUERY_VALUE, &hKey);
146 if (rc != ERROR_SUCCESS)
147 {
148 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
149 return FALSE;
150 }
151
152 Size = sizeof(Shell);
154 ConsoleShell ? L"ConsoleShell" : L"Shell",
155 NULL,
156 &Type,
157 (LPBYTE)Shell,
158 &Size);
160
161 if (rc != ERROR_SUCCESS)
162 {
163 WARN("RegQueryValueEx() failed with error %lu\n", rc);
164 return FALSE;
165 }
166
167 if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
168 {
169 TRACE("Found command line %s\n", debugstr_w(Shell));
170 wcscpy(CommandLine, Shell);
171 return TRUE;
172 }
173 else
174 {
175 WARN("Wrong type %lu (expected %u or %u)\n", Type, REG_SZ, REG_EXPAND_SZ);
176 return FALSE;
177 }
178}
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
short WCHAR
Definition: pedump.c:58
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:81
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

Referenced by StartShell().

◆ IsConsoleShell()

static BOOL IsConsoleShell ( VOID  )
static

Definition at line 81 of file userinit.c.

82{
83 HKEY ControlKey = NULL;
84 LPWSTR SystemStartOptions = NULL;
85 LPWSTR CurrentOption, NextOption; /* Pointers into SystemStartOptions */
86 LONG rc;
87 BOOL ret = FALSE;
88
89 rc = RegOpenKeyEx(
92 0,
94 &ControlKey);
95 if (rc != ERROR_SUCCESS)
96 {
97 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
98 goto cleanup;
99 }
100
101 rc = ReadRegSzKey(ControlKey, L"SystemStartOptions", &SystemStartOptions);
102 if (rc != ERROR_SUCCESS)
103 {
104 WARN("ReadRegSzKey() failed with error %lu\n", rc);
105 goto cleanup;
106 }
107
108 /* Check for CONSOLE switch in SystemStartOptions */
109 CurrentOption = SystemStartOptions;
110 while (CurrentOption)
111 {
112 NextOption = wcschr(CurrentOption, L' ');
113 if (NextOption)
114 *NextOption = L'\0';
115 if (_wcsicmp(CurrentOption, L"CONSOLE") == 0)
116 {
117 TRACE("Found 'CONSOLE' boot option\n");
118 ret = TRUE;
119 goto cleanup;
120 }
121 CurrentOption = NextOption ? NextOption + 1 : NULL;
122 }
123
124cleanup:
125 if (ControlKey != NULL)
126 RegCloseKey(ControlKey);
127 HeapFree(GetProcessHeap(), 0, SystemStartOptions);
128
129 TRACE("IsConsoleShell() returning %u\n", ret);
130 return ret;
131}
#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:164
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
uint16_t * LPWSTR
Definition: typedefs.h:56
LONG ReadRegSzKey(IN HKEY hKey, IN LPCWSTR pszKey, OUT LPWSTR *pValue)
Definition: userinit.c:39
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:552

Referenced by GetShell(), and StartShell().

◆ NotifyLogon()

static VOID NotifyLogon ( VOID  )
static

Definition at line 475 of file userinit.c.

476{
479
480 hModule = LoadLibraryW(L"setupapi.dll");
481 if (!hModule)
482 {
483 WARN("LoadLibrary() failed with error %lu\n", GetLastError());
484 return;
485 }
486
490 else
491 WARN("GetProcAddress() failed\n");
492
494}
CONFIGRET WINAPI CMP_Report_LogOn(_In_ DWORD dwMagic, _In_ DWORD dwProcessId)
Definition: cfgmgr.c:739
HMODULE hModule
Definition: animate.c:44
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD(WINAPI * PCMP_REPORT_LOGON)(DWORD, DWORD)
Definition: userinit.c:472
#define CMP_MAGIC
Definition: userinit.c:30
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1155

Referenced by wWinMain().

◆ ReadRegSzKey()

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

Definition at line 39 of file userinit.c.

43{
44 LONG rc;
45 DWORD dwType;
46 DWORD cbData = 0;
48
49 rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData);
50 if (rc != ERROR_SUCCESS)
51 {
52 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
53 return rc;
54 }
55 if (dwType != REG_SZ)
56 {
57 WARN("Wrong registry data type (%u vs %u)\n", dwType, REG_SZ);
59 }
60 Value = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
61 if (!Value)
62 {
63 WARN("No memory\n");
65 }
66 rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)Value, &cbData);
67 if (rc != ERROR_SUCCESS)
68 {
69 WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
71 return rc;
72 }
73 /* NULL-terminate the string */
74 Value[cbData / sizeof(WCHAR)] = L'\0';
75
76 *pValue = Value;
77 return ERROR_SUCCESS;
78}
#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 465 of file userinit.c.

466{
470}
DWORD WINAPI UpdatePerUserSystemParameters(DWORD dw1, DWORD dw2)
static VOID SetUserWallpaper(VOID)
Definition: userinit.c:424
static VOID SetUserSysColors(VOID)
Definition: userinit.c:386

Referenced by wWinMain().

◆ SetUserSysColors()

static VOID SetUserSysColors ( VOID  )
static

Definition at line 386 of file userinit.c.

387{
388 HKEY hKey;
389 INT i;
390 WCHAR szColor[25];
391 DWORD Type, Size;
392 COLORREF crColor;
393 LONG rc;
394
396 0, KEY_QUERY_VALUE, &hKey);
397 if (rc != ERROR_SUCCESS)
398 {
399 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
400 return;
401 }
402
403 for (i = 0; i < ARRAYSIZE(g_RegColorNames); i++)
404 {
405 Size = sizeof(szColor);
407 (LPBYTE)szColor, &Size);
408 if (rc == ERROR_SUCCESS && Type == REG_SZ)
409 {
410 crColor = StrToColorref(szColor);
411 SetSysColors(1, &i, &crColor);
412 }
413 else
414 {
415 WARN("RegQueryValueEx(%s) failed with error %lu\n",
417 }
418 }
419
421}
#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:339
static COLORREF StrToColorref(IN LPWSTR lpszCol)
Definition: userinit.c:374
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 424 of file userinit.c.

425{
426 HKEY hKey;
427 DWORD Type, Size;
428 WCHAR szWallpaper[MAX_PATH + 1];
429 LONG rc;
430
432 0, KEY_QUERY_VALUE, &hKey);
433 if (rc != ERROR_SUCCESS)
434 {
435 WARN("RegOpenKeyEx() failed with error %lu\n", rc);
436 return;
437 }
438
439 Size = sizeof(szWallpaper);
441 L"Wallpaper",
442 NULL,
443 &Type,
444 (LPBYTE)szWallpaper,
445 &Size);
447
448 if (rc == ERROR_SUCCESS && Type == REG_SZ)
449 {
450 ExpandEnvironmentStringsW(szWallpaper, szWallpaper, ARRAYSIZE(szWallpaper));
451 TRACE("Using wallpaper %s\n", debugstr_w(szWallpaper));
452
453 /* Load and change the wallpaper */
455 }
456 else
457 {
458 /* Remove the wallpaper */
459 TRACE("No wallpaper set in registry (error %lu)\n", rc);
461 }
462}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:492
#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 621 of file userinit.c.

622{
623 WCHAR Installer[MAX_PATH];
625
626 if (ExpandInstallerPath(lpInstallerName, Installer, ARRAYSIZE(Installer)))
627 {
628 /* We have found the installer */
629 if (StartProcess(Installer, NULL))
630 return TRUE;
631 }
632
633 /* We failed, display an error message and quit */
634 ERR("Failed to start the installer '%s'\n", debugstr_w(Installer));
636 MessageBoxW(NULL, szMsg, NULL, MB_OK);
637 return FALSE;
638}
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
#define IDS_INSTALLER_FAIL
Definition: resource.h:29
#define LoadStringW
Definition: utils.h:64
BOOL ExpandInstallerPath(IN LPCWSTR lpInstallerName, OUT LPWSTR lpInstallerPath, IN SIZE_T PathSize)
Definition: userinit.c:501
static BOOL StartProcess(_In_ PCWSTR CommandLine, _In_opt_ PVOID pEnvironment)
Definition: userinit.c:181
#define GetModuleHandle
Definition: winbase.h:3548
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_ PCWSTR  CommandLine,
_In_opt_ PVOID  pEnvironment 
)
static

Definition at line 181 of file userinit.c.

184{
187 WCHAR ExpandedCmdLine[MAX_PATH], ProfilePath[MAX_PATH];
188 HANDLE hToken;
190
191 ExpandEnvironmentStringsW(CommandLine, ExpandedCmdLine, ARRAYSIZE(ExpandedCmdLine));
192
193 ZeroMemory(&si, sizeof(si));
194 si.cb = sizeof(si);
195 si.dwFlags = STARTF_USESHOWWINDOW;
196 si.wShowWindow = SW_SHOWNORMAL;
197 ZeroMemory(&pi, sizeof(pi));
198
200 {
201 DWORD PathSize = _countof(ProfilePath);
202 if (GetUserProfileDirectoryW(hToken, ProfilePath, &PathSize))
203 WorkingDir = ProfilePath;
204 CloseHandle(hToken);
205 }
206
207 if (!CreateProcessW(NULL,
208 ExpandedCmdLine,
209 NULL,
210 NULL,
211 FALSE,
213 pEnvironment,
215 &si,
216 &pi))
217 {
218 WARN("CreateProcessW() failed with error %lu\n", GetLastError());
219 return FALSE;
220 }
221
224 return TRUE;
225}
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:4441
static const WCHAR WorkingDir[]
Definition: install.c:50
BOOL WINAPI GetUserProfileDirectoryW(_In_ HANDLE hToken, _Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1792
#define ZeroMemory
Definition: minwinbase.h:31
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39
#define _countof(array)
Definition: sndvol32.h:70
uint16_t * PWCHAR
Definition: typedefs.h:56
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:186
#define STARTF_USESHOWWINDOW
Definition: winbase.h:468
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:191
#define SW_SHOWNORMAL
Definition: winuser.h:781
#define TOKEN_QUERY
Definition: setypes.h:940

Referenced by StartInstaller(), and StartShell().

◆ StartShell()

static BOOL StartShell ( _In_opt_ PVOID  pEnvironment)
static

Definition at line 228 of file userinit.c.

230{
231 DWORD Type, Size;
232 DWORD Value = 0;
233 LONG rc;
234 HKEY hKey;
237
238 /* Safe Mode shell run */
240 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
241 0, KEY_QUERY_VALUE, &hKey);
242 if (rc == ERROR_SUCCESS)
243 {
244 Size = sizeof(Value);
245 rc = RegQueryValueExW(hKey, L"UseAlternateShell", NULL,
246 &Type, (LPBYTE)&Value, &Size);
248
249 if (rc == ERROR_SUCCESS)
250 {
251 if (Type == REG_DWORD)
252 {
253 if (Value)
254 {
255 /* Safe Mode Alternate Shell required */
257 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
258 0, KEY_READ, &hKey);
259 if (rc == ERROR_SUCCESS)
260 {
261 Size = sizeof(Shell);
262 rc = RegQueryValueExW(hKey, L"AlternateShell", NULL,
263 &Type, (LPBYTE)Shell, &Size);
265
266 if (rc == ERROR_SUCCESS)
267 {
268 if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
269 {
270 TRACE("Key located - %s\n", debugstr_w(Shell));
271
272 /* Try to run alternate shell */
273 if (StartProcess(Shell, pEnvironment))
274 {
275 TRACE("Alternate shell started (Safe Mode)\n");
276 return TRUE;
277 }
278 }
279 else
280 {
281 WARN("Wrong type %lu (expected %u or %u)\n",
283 }
284 }
285 else
286 {
287 WARN("Alternate shell in Safe Mode required but not specified.\n");
288 }
289 }
290 }
291 }
292 else
293 {
294 WARN("Wrong type %lu (expected %u)\n", Type, REG_DWORD);
295 }
296 }
297 }
298
299 /* Try to run shell in user key */
300 if (GetShell(Shell, HKEY_CURRENT_USER) && StartProcess(Shell, pEnvironment))
301 {
302 TRACE("Started shell from HKEY_CURRENT_USER\n");
303 return TRUE;
304 }
305
306 /* Try to run shell in local machine key */
307 if (GetShell(Shell, HKEY_LOCAL_MACHINE) && StartProcess(Shell, pEnvironment))
308 {
309 TRACE("Started shell from HKEY_LOCAL_MACHINE\n");
310 return TRUE;
311 }
312
313 /* Try default shell */
314 if (IsConsoleShell())
315 {
319 StringCchCatW(Shell, ARRAYSIZE(Shell), L"cmd.exe");
320 }
321 else
322 {
326 StringCchCatW(Shell, ARRAYSIZE(Shell), L"explorer.exe");
327 }
328
329 if (StartProcess(Shell, pEnvironment))
330 return TRUE;
331
332 /* We failed, display an error message and quit */
333 ERR("Failed to start default shell '%s'\n", debugstr_w(Shell));
335 MessageBoxW(NULL, szMsg, NULL, MB_OK);
336 return FALSE;
337}
#define IDS_SHELL_FAIL
Definition: resource.h:28
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
#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:134

Referenced by wWinMain().

◆ StrToColorref()

static COLORREF StrToColorref ( IN LPWSTR  lpszCol)
static

Definition at line 374 of file userinit.c.

376{
377 BYTE rgb[3];
378
379 rgb[0] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
380 rgb[1] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
381 rgb[2] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
382 return RGB(rgb[0], rgb[1], rgb[2]);
383}
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2917
#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 670 of file userinit.c.

674{
675 BOOL bIsLiveCD, Success = TRUE;
676 STATE State;
677
679
680 bIsLiveCD = IsLiveCD();
681
682Restart:
684
685 if (bIsLiveCD)
686 {
687 State.NextPage = LOCALEPAGE;
688 State.Run = SHELL;
689 }
690 else
691 {
692 State.NextPage = DONE;
693 State.Run = SHELL;
694 }
695
696 if (State.NextPage != DONE) // && bIsLiveCD
697 {
699 }
700
701 switch (State.Run)
702 {
703 case SHELL:
704 {
705 /* In LiveCD mode, create a suitable environment block for the
706 * shell; otherwise, use the current one (built by WinLogon) */
707 PVOID pEnvironment = NULL;
708 if (bIsLiveCD && /* In LiveCD mode we run under the LocalSystem account */
709 !CreateEnvironmentBlock(&pEnvironment, NULL, TRUE))
710 {
711 WARN("CreateEnvironmentBlock() failed, fall back to default (error %lu)\n",
712 GetLastError());
713 }
714 Success = StartShell(pEnvironment);
715 if (pEnvironment)
716 DestroyEnvironmentBlock(pEnvironment);
717 if (Success)
718 NotifyLogon();
719 break;
720 }
721
722 case INSTALLER:
723 Success = StartInstaller(L"reactos.exe");
724 break;
725
726 case REBOOT:
727 {
731 Success = TRUE;
732 break;
733 }
734
735 default:
736 Success = FALSE;
737 break;
738 }
739
740 /*
741 * In LiveCD mode, go back to the main menu if we failed
742 * to either start the shell or the installer.
743 */
744 if (bIsLiveCD && !Success)
745 goto Restart;
746
747 return 0;
748}
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:725
BOOL WINAPI CreateEnvironmentBlock(OUT LPVOID *lpEnvironment, IN HANDLE hToken, IN BOOL bInherit)
Definition: environment.c:503
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:465
static BOOL EnablePrivilege(LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
Definition: userinit.c:642
static BOOL StartShell(_In_opt_ PVOID pEnvironment)
Definition: userinit.c:228
HINSTANCE hInstance
Definition: userinit.c:34
static VOID NotifyLogon(VOID)
Definition: userinit.c:475
static BOOL StartInstaller(IN LPCWSTR lpInstallerName)
Definition: userinit.c:621
@ 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:427
#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 339 of file userinit.c.

Referenced by SetUserSysColors().

◆ hInstance

HINSTANCE hInstance

Definition at line 34 of file userinit.c.

Referenced by wWinMain().