f631a2013fb5c932b5b291b76eff25a8fa95ba7f
[reactos.git] / reactos / subsys / 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
30 /* GLOBALS ******************************************************************/
31
32 /* FUNCTIONS ****************************************************************/
33
34 static
35 BOOL GetShell(WCHAR *CommandLine)
36 {
37 HKEY hKey;
38 DWORD Type, Size;
39 WCHAR Shell[MAX_PATH];
40 BOOL Ret = FALSE;
41
42 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
43 L"SOFTWARE\\ReactOS\\Windows NT\\CurrentVersion\\Winlogon",
44 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
45 {
46 Size = MAX_PATH * sizeof(WCHAR);
47 if(RegQueryValueEx(hKey,
48 L"Shell",
49 NULL,
50 &Type,
51 (LPBYTE)Shell,
52 &Size) == ERROR_SUCCESS)
53 {
54 if((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
55 {
56 wcscpy(CommandLine, Shell);
57 Ret = TRUE;
58 }
59 }
60 RegCloseKey(hKey);
61 }
62
63 if(!Ret)
64 {
65 if(GetWindowsDirectory(CommandLine, MAX_PATH - 13))
66 wcscat(CommandLine, L"\\explorer.exe");
67 else
68 wcscpy(CommandLine, L"explorer.exe");
69 }
70
71 return Ret;
72 }
73
74 static
75 void StartShell(void)
76 {
77 STARTUPINFO si;
78 PROCESS_INFORMATION pi;
79 WCHAR Shell[MAX_PATH];
80 WCHAR ExpandedShell[MAX_PATH];
81 TCHAR szMsg[RC_STRING_MAX_SIZE];
82
83 GetShell(Shell);
84
85 ZeroMemory(&si, sizeof(STARTUPINFO));
86 si.cb = sizeof(STARTUPINFO);
87 ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
88
89 ExpandEnvironmentStrings(Shell, ExpandedShell, MAX_PATH);
90
91 if(CreateProcess(NULL,
92 ExpandedShell,
93 NULL,
94 NULL,
95 FALSE,
96 NORMAL_PRIORITY_CLASS,
97 NULL,
98 NULL,
99 &si,
100 &pi))
101 {
102 WaitForSingleObject(pi.hProcess, INFINITE);
103 CloseHandle(pi.hProcess);
104 CloseHandle(pi.hThread);
105 }
106 else
107 {
108 LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
109 MessageBox(0, szMsg, NULL, 0);
110 }
111 }
112
113 static
114 void SetUserSettings(void)
115 {
116 HKEY hKey;
117 DWORD Type, Size;
118 WCHAR szWallpaper[MAX_PATH + 1];
119
120 if(RegOpenKeyEx(HKEY_CURRENT_USER,
121 L"Control Panel\\Desktop",
122 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
123 {
124 Size = sizeof(szWallpaper);
125 if(RegQueryValueEx(hKey,
126 L"Wallpaper",
127 NULL,
128 &Type,
129 (LPBYTE)szWallpaper,
130 &Size) == ERROR_SUCCESS
131 && Type == REG_SZ)
132 {
133 /* Load and change the wallpaper */
134 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, szWallpaper, SPIF_SENDCHANGE);
135 }
136 else
137 {
138 /* remove the wallpaper */
139 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
140 }
141 RegCloseKey(hKey);
142 }
143 }
144
145
146 typedef DWORD (WINAPI *PCMP_REPORT_LOGON)(DWORD, DWORD);
147
148 static VOID
149 NotifyLogon(VOID)
150 {
151 HINSTANCE hModule;
152 PCMP_REPORT_LOGON CMP_Report_LogOn;
153
154 hModule = LoadLibrary(L"setupapi.dll");
155 if (hModule)
156 {
157 CMP_Report_LogOn = (PCMP_REPORT_LOGON)GetProcAddress(hModule, "CMP_Report_LogOn");
158 if (CMP_Report_LogOn)
159 CMP_Report_LogOn(CMP_MAGIC, GetCurrentProcessId());
160
161 FreeLibrary(hModule);
162 }
163 }
164
165
166 #ifdef _MSC_VER
167 #pragma warning(disable : 4100)
168 #endif /* _MSC_VER */
169
170 int WINAPI
171 WinMain(HINSTANCE hInst,
172 HINSTANCE hPrevInstance,
173 LPSTR lpszCmdLine,
174 int nCmdShow)
175 {
176 NotifyLogon();
177 SetUserSettings();
178 StartShell();
179 return 0;
180 }
181
182 /* EOF */