Hauled subsys/system items into base/system
[reactos.git] / reactos / base / system / userinit / userinit.c
1 /*
2 * ReactOS applications
3 * Copyright (C) 2001, 2002 ReactOS Team
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Userinit Logon Application
22 * FILE: subsys/system/userinit/userinit.c
23 * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
24 */
25 #include <windows.h>
26 #include <cfgmgr32.h>
27 #include "resource.h"
28
29 #define CMP_MAGIC 0x01234567
30
31 /* GLOBALS ******************************************************************/
32
33 /* FUNCTIONS ****************************************************************/
34
35 static
36 BOOL GetShell(WCHAR *CommandLine)
37 {
38 HKEY hKey;
39 DWORD Type, Size;
40 WCHAR Shell[MAX_PATH];
41 BOOL Ret = FALSE;
42
43 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
44 L"SOFTWARE\\ReactOS\\Windows NT\\CurrentVersion\\Winlogon",
45 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
46 {
47 Size = MAX_PATH * sizeof(WCHAR);
48 if(RegQueryValueEx(hKey,
49 L"Shell",
50 NULL,
51 &Type,
52 (LPBYTE)Shell,
53 &Size) == ERROR_SUCCESS)
54 {
55 if((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
56 {
57 wcscpy(CommandLine, Shell);
58 Ret = TRUE;
59 }
60 }
61 RegCloseKey(hKey);
62 }
63
64 if(!Ret)
65 {
66 if(GetWindowsDirectory(CommandLine, MAX_PATH - 13))
67 wcscat(CommandLine, L"\\explorer.exe");
68 else
69 wcscpy(CommandLine, L"explorer.exe");
70 }
71
72 return Ret;
73 }
74
75 static
76 void StartShell(void)
77 {
78 STARTUPINFO si;
79 PROCESS_INFORMATION pi;
80 WCHAR Shell[MAX_PATH];
81 WCHAR ExpandedShell[MAX_PATH];
82 TCHAR szMsg[RC_STRING_MAX_SIZE];
83
84 GetShell(Shell);
85
86 ZeroMemory(&si, sizeof(STARTUPINFO));
87 si.cb = sizeof(STARTUPINFO);
88 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
89
90 ExpandEnvironmentStrings(Shell, ExpandedShell, MAX_PATH);
91
92 if(CreateProcess(NULL,
93 ExpandedShell,
94 NULL,
95 NULL,
96 FALSE,
97 NORMAL_PRIORITY_CLASS,
98 NULL,
99 NULL,
100 &si,
101 &pi))
102 {
103 WaitForSingleObject(pi.hProcess, INFINITE);
104 CloseHandle(pi.hProcess);
105 CloseHandle(pi.hThread);
106 }
107 else
108 {
109 LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
110 MessageBox(0, szMsg, NULL, 0);
111 }
112 }
113
114 static
115 void SetUserSettings(void)
116 {
117 HKEY hKey;
118 DWORD Type, Size;
119 WCHAR szWallpaper[MAX_PATH + 1];
120
121 if(RegOpenKeyEx(HKEY_CURRENT_USER,
122 L"Control Panel\\Desktop",
123 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
124 {
125 Size = sizeof(szWallpaper);
126 if(RegQueryValueEx(hKey,
127 L"Wallpaper",
128 NULL,
129 &Type,
130 (LPBYTE)szWallpaper,
131 &Size) == ERROR_SUCCESS
132 && Type == REG_SZ)
133 {
134 /* Load and change the wallpaper */
135 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, szWallpaper, SPIF_SENDCHANGE);
136 }
137 else
138 {
139 /* remove the wallpaper */
140 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
141 }
142 RegCloseKey(hKey);
143 }
144 }
145
146
147 typedef DWORD (WINAPI *PCMP_REPORT_LOGON)(DWORD, DWORD);
148
149 static VOID
150 NotifyLogon(VOID)
151 {
152 HINSTANCE hModule;
153 PCMP_REPORT_LOGON CMP_Report_LogOn;
154
155 hModule = LoadLibrary(L"setupapi.dll");
156 if (hModule)
157 {
158 CMP_Report_LogOn = (PCMP_REPORT_LOGON)GetProcAddress(hModule, "CMP_Report_LogOn");
159 if (CMP_Report_LogOn)
160 CMP_Report_LogOn(CMP_MAGIC, GetCurrentProcessId());
161
162 FreeLibrary(hModule);
163 }
164 }
165
166
167 #ifdef _MSC_VER
168 #pragma warning(disable : 4100)
169 #endif /* _MSC_VER */
170
171 int WINAPI
172 WinMain(HINSTANCE hInst,
173 HINSTANCE hPrevInstance,
174 LPSTR lpszCmdLine,
175 int nCmdShow)
176 {
177 NotifyLogon();
178 SetUserSettings();
179 StartShell();
180 return 0;
181 }
182
183 /* EOF */