Copy w32api from trunk
[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 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS Userinit Logon Application
23 * FILE: subsys/system/userinit/userinit.c
24 * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 */
26 #include <windows.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, (LPTSTR) szMsg,sizeof(szMsg));
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 int WINAPI
146 WinMain(HINSTANCE hInst,
147 HINSTANCE hPrevInstance,
148 LPSTR lpszCmdLine,
149 int nCmdShow)
150 {
151 SetUserSettings();
152 StartShell();
153 return 0;
154 }
155
156 /* EOF */