ReactOS  0.4.14-dev-49-gfb4591c
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)
 
static BOOL StartInstaller (IN LPCTSTR 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 477 of file userinit.c.

Function Documentation

◆ EnablePrivilege()

static BOOL EnablePrivilege ( LPCWSTR  lpszPrivilegeName,
BOOL  bEnablePrivilege 
)
static

Definition at line 626 of file userinit.c.

627 {
628  BOOL Success;
629  HANDLE hToken;
631 
634  &hToken);
635  if (!Success) return Success;
636 
638  lpszPrivilegeName,
639  &tp.Privileges[0].Luid);
640  if (!Success) goto Quit;
641 
642  tp.PrivilegeCount = 1;
643  tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0);
644 
645  Success = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
646 
647 Quit:
648  CloseHandle(hToken);
649  return Success;
650 }
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876

Referenced by wWinMain().

◆ GetShell()

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

Definition at line 137 of file userinit.c.

140 {
141  HKEY hKey;
142  DWORD Type, Size;
144  BOOL ConsoleShell = IsConsoleShell();
145  LONG rc;
146 
147  TRACE("(%p, %p)\n", CommandLine, hRootKey);
148 
149  rc = RegOpenKeyExW(hRootKey, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
150  0, KEY_QUERY_VALUE, &hKey);
151  if (rc != ERROR_SUCCESS)
152  {
153  WARN("RegOpenKeyEx() failed with error %lu\n", rc);
154  return FALSE;
155  }
156 
157  Size = sizeof(Shell);
158  rc = RegQueryValueExW(hKey,
159  ConsoleShell ? L"ConsoleShell" : L"Shell",
160  NULL,
161  &Type,
162  (LPBYTE)Shell,
163  &Size);
164  RegCloseKey(hKey);
165 
166  if (rc != ERROR_SUCCESS)
167  {
168  WARN("RegQueryValueEx() failed with error %lu\n", rc);
169  return FALSE;
170  }
171 
172  if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
173  {
174  TRACE("Found command line %s\n", debugstr_w(Shell));
175  wcscpy(CommandLine, Shell);
176  return TRUE;
177  }
178  else
179  {
180  WARN("Wrong type %lu (expected %u or %u)\n", Type, REG_SZ, REG_EXPAND_SZ);
181  return FALSE;
182  }
183 }
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WARN(fmt,...)
Definition: debug.h:111
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static BOOL IsConsoleShell(VOID)
Definition: userinit.c:83
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
static int Shell(const char **args)
Definition: vfdcmd.c:1020
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define REG_SZ
Definition: layer.c:22

Referenced by StartShell().

◆ IsConsoleShell()

static BOOL IsConsoleShell ( VOID  )
static

Definition at line 83 of file userinit.c.

84 {
85  HKEY ControlKey = NULL;
86  LPWSTR SystemStartOptions = NULL;
87  LPWSTR CurrentOption, NextOption; /* Pointers into SystemStartOptions */
88  LONG rc;
89  BOOL ret = FALSE;
90 
91  TRACE("()\n");
92 
93  rc = RegOpenKeyEx(
96  0,
98  &ControlKey);
99  if (rc != ERROR_SUCCESS)
100  {
101  WARN("RegOpenKeyEx() failed with error %lu\n", rc);
102  goto cleanup;
103  }
104 
105  rc = ReadRegSzKey(ControlKey, L"SystemStartOptions", &SystemStartOptions);
106  if (rc != ERROR_SUCCESS)
107  {
108  WARN("ReadRegSzKey() failed with error %lu\n", rc);
109  goto cleanup;
110  }
111 
112  /* Check for CONSOLE switch in SystemStartOptions */
113  CurrentOption = SystemStartOptions;
114  while (CurrentOption)
115  {
116  NextOption = wcschr(CurrentOption, L' ');
117  if (NextOption)
118  *NextOption = L'\0';
119  if (_wcsicmp(CurrentOption, L"CONSOLE") == 0)
120  {
121  TRACE("Found 'CONSOLE' boot option\n");
122  ret = TRUE;
123  goto cleanup;
124  }
125  CurrentOption = NextOption ? NextOption + 1 : NULL;
126  }
127 
128 cleanup:
129  if (ControlKey != NULL)
130  RegCloseKey(ControlKey);
131  HeapFree(GetProcessHeap(), 0, SystemStartOptions);
132  TRACE("IsConsoleShell() returning %d\n", ret);
133  return ret;
134 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WARN(fmt,...)
Definition: debug.h:111
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define RegOpenKeyEx
Definition: winreg.h:520
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LONG ReadRegSzKey(IN HKEY hKey, IN LPCWSTR pszKey, OUT LPWSTR *pValue)
Definition: userinit.c:39
#define REGSTR_PATH_CURRENT_CONTROL_SET
Definition: regstr.h:564
char * cleanup(char *str)
Definition: wpickclick.c:99
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by GetShell(), and StartShell().

◆ NotifyLogon()

static VOID NotifyLogon ( VOID  )
static

Definition at line 480 of file userinit.c.

481 {
484 
485  TRACE("()\n");
486 
487  hModule = LoadLibraryW(L"setupapi.dll");
488  if (!hModule)
489  {
490  WARN("LoadLibrary() failed with error %lu\n", GetLastError());
491  return;
492  }
493 
495  if (CMP_Report_LogOn)
497  else
498  WARN("GetProcAddress() failed\n");
499 
501 }
#define WARN(fmt,...)
Definition: debug.h:111
#define CMP_MAGIC
Definition: userinit.c:29
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define LoadLibraryW(x)
Definition: compat.h:404
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:405
static const WCHAR L[]
Definition: oid.c:1250
CONFIGRET WINAPI CMP_Report_LogOn(_In_ DWORD dwMagic, _In_ DWORD dwProcessId)
Definition: cfgmgr.c:705
DWORD(WINAPI * PCMP_REPORT_LOGON)(DWORD, DWORD)
Definition: userinit.c:477
#define GetProcAddress(x, y)
Definition: compat.h:410
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
HMODULE hModule
Definition: animate.c:44

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;
47  LPWSTR Value;
48 
49  TRACE("(%p, %s, %p)\n", hKey, debugstr_w(pszKey), pValue);
50 
51  rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData);
52  if (rc != ERROR_SUCCESS)
53  {
54  WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
55  return rc;
56  }
57  if (dwType != REG_SZ)
58  {
59  WARN("Wrong registry data type (%u vs %u)\n", dwType, REG_SZ);
60  return ERROR_FILE_NOT_FOUND;
61  }
62  Value = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
63  if (!Value)
64  {
65  WARN("No memory\n");
67  }
68  rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)Value, &cbData);
69  if (rc != ERROR_SUCCESS)
70  {
71  WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
73  return rc;
74  }
75  /* NULL-terminate the string */
76  Value[cbData / sizeof(WCHAR)] = L'\0';
77 
78  *pValue = Value;
79  return ERROR_SUCCESS;
80 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WARN(fmt,...)
Definition: debug.h:111
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
#define REG_SZ
Definition: layer.c:22

Referenced by IsConsoleShell().

◆ SetUserSettings()

static VOID SetUserSettings ( VOID  )
static

Definition at line 468 of file userinit.c.

469 {
470  TRACE("()\n");
471 
475 }
#define TRUE
Definition: types.h:120
static VOID SetUserWallpaper(VOID)
Definition: userinit.c:425
#define TRACE(s)
Definition: solgame.cpp:4
DWORD WINAPI UpdatePerUserSystemParameters(DWORD dw1, DWORD dw2)
static VOID SetUserSysColors(VOID)
Definition: userinit.c:385

Referenced by wWinMain().

◆ SetUserSysColors()

static VOID SetUserSysColors ( VOID  )
static

Definition at line 385 of file userinit.c.

386 {
387  HKEY hKey;
388  INT i;
389  WCHAR szColor[25];
390  DWORD Type, Size;
391  COLORREF crColor;
392  LONG rc;
393 
394  TRACE("()\n");
395 
397  0, KEY_QUERY_VALUE, &hKey);
398  if (rc != ERROR_SUCCESS)
399  {
400  WARN("RegOpenKeyEx() failed with error %lu\n", rc);
401  return;
402  }
403 
404  for (i = 0; i < ARRAYSIZE(g_RegColorNames); i++)
405  {
406  Size = sizeof(szColor);
407  rc = RegQueryValueExW(hKey, g_RegColorNames[i], NULL, &Type,
408  (LPBYTE)szColor, &Size);
409  if (rc == ERROR_SUCCESS && Type == REG_SZ)
410  {
411  crColor = StrToColorref(szColor);
412  SetSysColors(1, &i, &crColor);
413  }
414  else
415  {
416  WARN("RegQueryValueEx(%s) failed with error %lu\n",
418  }
419  }
420 
421  RegCloseKey(hKey);
422 }
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define REGSTR_PATH_COLORS
Definition: regstr.h:662
int32_t INT
Definition: typedefs.h:56
static COLORREF StrToColorref(IN LPWSTR lpszCol)
Definition: userinit.c:371
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD COLORREF
Definition: windef.h:285
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI SetSysColors(_In_ int cElements, _In_reads_(cElements) CONST INT *lpaElements, _In_reads_(cElements) CONST COLORREF *lpaRgbValues)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
const WCHAR g_RegColorNames[][32]
Definition: userinit.c:336
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define REG_SZ
Definition: layer.c:22

Referenced by SetUserSettings().

◆ SetUserWallpaper()

static VOID SetUserWallpaper ( VOID  )
static

Definition at line 425 of file userinit.c.

426 {
427  HKEY hKey;
428  DWORD Type, Size;
429  WCHAR szWallpaper[MAX_PATH + 1];
430  LONG rc;
431 
432  TRACE("()\n");
433 
435  0, KEY_QUERY_VALUE, &hKey);
436  if (rc != ERROR_SUCCESS)
437  {
438  WARN("RegOpenKeyEx() failed with error %lu\n", rc);
439  return;
440  }
441 
442  Size = sizeof(szWallpaper);
443  rc = RegQueryValueExW(hKey,
444  L"Wallpaper",
445  NULL,
446  &Type,
447  (LPBYTE)szWallpaper,
448  &Size);
449  RegCloseKey(hKey);
450 
451  if (rc == ERROR_SUCCESS && Type == REG_SZ)
452  {
453  ExpandEnvironmentStringsW(szWallpaper, szWallpaper, ARRAYSIZE(szWallpaper));
454  TRACE("Using wallpaper %s\n", debugstr_w(szWallpaper));
455 
456  /* Load and change the wallpaper */
458  }
459  else
460  {
461  /* Remove the wallpaper */
462  TRACE("No wallpaper set in registry (error %lu)\n", rc);
464  }
465 }
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SPI_SETDESKWALLPAPER
Definition: winuser.h:1351
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SystemParametersInfoW(_In_ UINT, _In_ UINT, _Inout_opt_ PVOID, _In_ UINT)
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define SPIF_SENDCHANGE
Definition: winuser.h:1554
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define REGSTR_PATH_DESKTOP
Definition: regstr.h:659
#define REG_SZ
Definition: layer.c:22

Referenced by SetUserSettings().

◆ StartInstaller()

static BOOL StartInstaller ( IN LPCTSTR  lpInstallerName)
static

Definition at line 504 of file userinit.c.

505 {
506  SYSTEM_INFO SystemInfo;
507  SIZE_T cchInstallerNameLen;
508  PWSTR ptr;
509  DWORD dwAttribs;
510  WCHAR Installer[MAX_PATH];
511  WCHAR szMsg[RC_STRING_MAX_SIZE];
512 
513  cchInstallerNameLen = wcslen(lpInstallerName);
514  if (ARRAYSIZE(Installer) < cchInstallerNameLen)
515  {
516  /* The buffer is not large enough to contain the installer file name */
517  return FALSE;
518  }
519 
520  /*
521  * First, try to find the installer using the default drive, under
522  * the directory whose name corresponds to the currently-running
523  * CPU architecture.
524  */
525  GetSystemInfo(&SystemInfo);
526 
527  *Installer = UNICODE_NULL;
528  /* Alternatively one can use SharedUserData->NtSystemRoot */
529  GetSystemWindowsDirectoryW(Installer, ARRAYSIZE(Installer) - cchInstallerNameLen - 1);
530  ptr = wcschr(Installer, L'\\');
531  if (ptr)
532  *++ptr = UNICODE_NULL;
533  else
534  *Installer = UNICODE_NULL;
535 
536  /* Append the corresponding CPU architecture */
537  switch (SystemInfo.wProcessorArchitecture)
538  {
540  StringCchCatW(Installer, ARRAYSIZE(Installer), L"I386");
541  break;
542 
544  StringCchCatW(Installer, ARRAYSIZE(Installer), L"MIPS");
545  break;
546 
548  StringCchCatW(Installer, ARRAYSIZE(Installer), L"ALPHA");
549  break;
550 
552  StringCchCatW(Installer, ARRAYSIZE(Installer), L"PPC");
553  break;
554 
556  StringCchCatW(Installer, ARRAYSIZE(Installer), L"SHX");
557  break;
558 
560  StringCchCatW(Installer, ARRAYSIZE(Installer), L"ARM");
561  break;
562 
564  StringCchCatW(Installer, ARRAYSIZE(Installer), L"IA64");
565  break;
566 
568  StringCchCatW(Installer, ARRAYSIZE(Installer), L"ALPHA64");
569  break;
570 
572  StringCchCatW(Installer, ARRAYSIZE(Installer), L"AMD64");
573  break;
574 
575  // case PROCESSOR_ARCHITECTURE_MSIL: /* .NET CPU-independent code */
577  default:
578  WARN("Unknown processor architecture %lu\n", SystemInfo.wProcessorArchitecture);
580  break;
581  }
582 
584  StringCchCatW(Installer, ARRAYSIZE(Installer), L"\\");
585  StringCchCatW(Installer, ARRAYSIZE(Installer), lpInstallerName);
586 
587  dwAttribs = GetFileAttributesW(Installer);
588  if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
589  !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
590  {
591  /* We have found the installer */
592  if (StartProcess(Installer))
593  return TRUE;
594  }
595 
596  ERR("Failed to start the installer '%s', trying alternative.\n", debugstr_w(Installer));
597 
598  /*
599  * We failed. Try to find the installer from either the current
600  * ReactOS installation directory, or from our current directory.
601  */
602  *Installer = UNICODE_NULL;
603  /* Alternatively one can use SharedUserData->NtSystemRoot */
604  if (GetSystemWindowsDirectoryW(Installer, ARRAYSIZE(Installer) - cchInstallerNameLen - 1))
605  StringCchCatW(Installer, ARRAYSIZE(Installer), L"\\");
606  StringCchCatW(Installer, ARRAYSIZE(Installer), lpInstallerName);
607 
608  dwAttribs = GetFileAttributesW(Installer);
609  if ((dwAttribs != INVALID_FILE_ATTRIBUTES) &&
610  !(dwAttribs & FILE_ATTRIBUTE_DIRECTORY))
611  {
612  /* We have found the installer */
613  if (StartProcess(Installer))
614  return TRUE;
615  }
616 
617  /* We failed. Display an error message and quit. */
618  ERR("Failed to start the installer '%s'.\n", debugstr_w(Installer));
620  MessageBoxW(NULL, szMsg, NULL, MB_OK);
621  return FALSE;
622 }
UINT WINAPI GetSystemWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2396
#define TRUE
Definition: types.h:120
#define PROCESSOR_ARCHITECTURE_SHX
Definition: ketypes.h:109
#define IDS_INSTALLER_FAIL
Definition: resource.h:29
#define PROCESSOR_ARCHITECTURE_ARM
Definition: ketypes.h:110
#define PROCESSOR_ARCHITECTURE_UNKNOWN
Definition: ketypes.h:115
uint16_t * PWSTR
Definition: typedefs.h:54
#define WARN(fmt,...)
Definition: debug.h:111
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define PROCESSOR_ARCHITECTURE_MIPS
Definition: ketypes.h:106
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define PROCESSOR_ARCHITECTURE_ALPHA64
Definition: ketypes.h:112
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
#define PROCESSOR_ARCHITECTURE_ALPHA
Definition: ketypes.h:107
#define UNICODE_NULL
static BOOL StartProcess(IN LPCWSTR CommandLine)
Definition: userinit.c:186
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
static const WCHAR L[]
Definition: oid.c:1250
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define GetModuleHandle
Definition: winbase.h:3644
#define PROCESSOR_ARCHITECTURE_PPC
Definition: ketypes.h:108
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
#define MB_OK
Definition: winuser.h:784
WORD wProcessorArchitecture
Definition: winbase.h:1122
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RC_STRING_MAX_SIZE
Definition: resource.h:3

Referenced by wWinMain().

◆ StartProcess()

static BOOL StartProcess ( IN LPCWSTR  CommandLine)
static

Definition at line 186 of file userinit.c.

188 {
189  STARTUPINFO si;
191  WCHAR ExpandedCmdLine[MAX_PATH];
192 
193  TRACE("(%s)\n", debugstr_w(CommandLine));
194 
195  ExpandEnvironmentStringsW(CommandLine, ExpandedCmdLine, ARRAYSIZE(ExpandedCmdLine));
196 
197  ZeroMemory(&si, sizeof(si));
198  si.cb = sizeof(si);
201  ZeroMemory(&pi, sizeof(pi));
202 
203  if (!CreateProcessW(NULL,
204  ExpandedCmdLine,
205  NULL,
206  NULL,
207  FALSE,
209  NULL,
210  NULL,
211  &si,
212  &pi))
213  {
214  WARN("CreateProcessW() failed with error %lu\n", GetLastError());
215  return FALSE;
216  }
217 
218  CloseHandle(pi.hProcess);
219  CloseHandle(pi.hThread);
220  return TRUE;
221 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define WARN(fmt,...)
Definition: debug.h:111
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
DWORD dwFlags
Definition: winbase.h:807
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
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:4593
#define TRACE(s)
Definition: solgame.cpp:4
DWORD cb
Definition: winbase.h:796
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
static DWORD pi
Definition: protocol.c:150
#define SW_SHOWNORMAL
Definition: winuser.h:764
WORD wShowWindow
Definition: winbase.h:808
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519

Referenced by StartInstaller(), and StartShell().

◆ StartShell()

static BOOL StartShell ( VOID  )
static

Definition at line 224 of file userinit.c.

225 {
227  WCHAR szMsg[RC_STRING_MAX_SIZE];
228  DWORD Type, Size;
229  DWORD Value = 0;
230  LONG rc;
231  HKEY hKey;
232 
233  TRACE("()\n");
234 
235  /* Safe Mode shell run */
237  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
238  0, KEY_QUERY_VALUE, &hKey);
239  if (rc == ERROR_SUCCESS)
240  {
241  Size = sizeof(Value);
242  rc = RegQueryValueExW(hKey, L"UseAlternateShell", NULL,
243  &Type, (LPBYTE)&Value, &Size);
244  RegCloseKey(hKey);
245 
246  if (rc == ERROR_SUCCESS)
247  {
248  if (Type == REG_DWORD)
249  {
250  if (Value)
251  {
252  /* Safe Mode Alternate Shell required */
254  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
255  0, KEY_READ, &hKey);
256  if (rc == ERROR_SUCCESS)
257  {
258  Size = sizeof(Shell);
259  rc = RegQueryValueExW(hKey, L"AlternateShell", NULL,
260  &Type, (LPBYTE)Shell, &Size);
261  RegCloseKey(hKey);
262 
263  if (rc == ERROR_SUCCESS)
264  {
265  if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
266  {
267  TRACE("Key located - %s\n", debugstr_w(Shell));
268 
269  /* Try to run alternate shell */
270  if (StartProcess(Shell))
271  {
272  TRACE("Alternate shell started (Safe Mode)\n");
273  return TRUE;
274  }
275  }
276  else
277  {
278  WARN("Wrong type %lu (expected %u or %u)\n",
280  }
281  }
282  else
283  {
284  WARN("Alternate shell in Safe Mode required but not specified.");
285  }
286  }
287  }
288  }
289  else
290  {
291  WARN("Wrong type %lu (expected %u)\n", Type, REG_DWORD);
292  }
293  }
294  }
295 
296  /* Try to run shell in user key */
298  {
299  TRACE("Started shell from HKEY_CURRENT_USER\n");
300  return TRUE;
301  }
302 
303  /* Try to run shell in local machine key */
305  {
306  TRACE("Started shell from HKEY_LOCAL_MACHINE\n");
307  return TRUE;
308  }
309 
310  /* Try default shell */
311  if (IsConsoleShell())
312  {
313  *Shell = UNICODE_NULL;
316  StringCchCatW(Shell, ARRAYSIZE(Shell), L"cmd.exe");
317  }
318  else
319  {
320  *Shell = UNICODE_NULL;
323  StringCchCatW(Shell, ARRAYSIZE(Shell), L"explorer.exe");
324  }
325 
326  if (!StartProcess(Shell))
327  {
328  WARN("Failed to start default shell '%s'\n", debugstr_w(Shell));
330  MessageBoxW(NULL, szMsg, NULL, MB_OK);
331  return FALSE;
332  }
333  return TRUE;
334 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define IDS_SHELL_FAIL
Definition: resource.h:28
UINT WINAPI GetSystemWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2396
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define WARN(fmt,...)
Definition: debug.h:111
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define UNICODE_NULL
static BOOL StartProcess(IN LPCWSTR CommandLine)
Definition: userinit.c:186
long LONG
Definition: pedump.c:60
static BOOL GetShell(OUT WCHAR *CommandLine, IN HKEY hRootKey)
Definition: userinit.c:137
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static BOOL IsConsoleShell(VOID)
Definition: userinit.c:83
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
static int Shell(const char **args)
Definition: vfdcmd.c:1020
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define GetModuleHandle
Definition: winbase.h:3644
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
#define MB_OK
Definition: winuser.h:784
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define REG_DWORD
Definition: sdbapi.c:596
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
#define REG_SZ
Definition: layer.c:22

Referenced by wWinMain().

◆ StrToColorref()

static COLORREF StrToColorref ( IN LPWSTR  lpszCol)
static

Definition at line 371 of file userinit.c.

373 {
374  BYTE rgb[3];
375 
376  TRACE("(%s)\n", debugstr_w(lpszCol));
377 
378  rgb[0] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
379  rgb[1] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
380  rgb[2] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
381  return RGB(rgb[0], rgb[1], rgb[2]);
382 }
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define RGB(r, g, b)
Definition: wingdi.h:2935
unsigned char BYTE
Definition: mem.h:68
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3520

Referenced by SetUserSysColors().

◆ wWinMain()

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

Definition at line 654 of file userinit.c.

658 {
659  BOOL bIsLiveCD, Success = TRUE;
660  STATE State;
661 
662  hInstance = hInst;
663 
664  bIsLiveCD = IsLiveCD();
665 
666 Restart:
667  SetUserSettings();
668 
669  if (bIsLiveCD)
670  {
671  State.NextPage = LOCALEPAGE;
672  State.Run = SHELL;
673  }
674  else
675  {
676  State.NextPage = DONE;
677  State.Run = SHELL;
678  }
679 
680  if (State.NextPage != DONE) // && bIsLiveCD
681  {
682  RunLiveCD(&State);
683  }
684 
685  switch (State.Run)
686  {
687  case SHELL:
688  Success = StartShell();
689  if (Success)
690  NotifyLogon();
691  break;
692 
693  case INSTALLER:
694  Success = StartInstaller(L"reactos.exe");
695  break;
696 
697  case REBOOT:
698  {
702  Success = TRUE;
703  break;
704  }
705 
706  default:
707  Success = FALSE;
708  break;
709  }
710 
711  /*
712  * In LiveCD mode, go back to the main menu if we failed
713  * to either start the shell or the installer.
714  */
715  if (bIsLiveCD && !Success)
716  goto Restart;
717 
718  return 0;
719 }
#define TRUE
Definition: types.h:120
Definition: userinit.h:56
static VOID SetUserSettings(VOID)
Definition: userinit.c:468
#define EWX_REBOOT
Definition: winuser.h:633
VOID RunLiveCD(PSTATE pState)
Definition: livecd.c:810
static BOOL StartInstaller(IN LPCTSTR lpInstallerName)
Definition: userinit.c:504
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID NotifyLogon(VOID)
Definition: userinit.c:480
Definition: userinit.h:42
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
enum State_ State
Definition: pofuncs.h:54
HINSTANCE hInst
Definition: dxdiag.c:13
static BOOL StartShell(VOID)
Definition: userinit.c:224
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:383
#define DONE
Definition: rnr20lib.h:14
BOOL IsLiveCD(VOID)
Definition: livecd.c:92
static BOOL EnablePrivilege(LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
Definition: userinit.c:626
HINSTANCE hInstance
Definition: userinit.c:33

Variable Documentation

◆ g_RegColorNames

const WCHAR g_RegColorNames[][32]

Definition at line 336 of file userinit.c.

Referenced by SetUserSysColors().

◆ hInstance

HINSTANCE hInstance

Definition at line 33 of file userinit.c.

Referenced by wWinMain().