3 * Copyright (C) 2001, 2002 ReactOS Team
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.
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.
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.
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 * Hervé Poussineau (hpoussin@reactos.org)
31 #define CMP_MAGIC 0x01234567
33 /* GLOBALS ******************************************************************/
35 /* FUNCTIONS ****************************************************************/
48 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
49 if (rc
!= ERROR_SUCCESS
)
52 return ERROR_FILE_NOT_FOUND
;
53 Value
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
55 return ERROR_NOT_ENOUGH_MEMORY
;
56 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)Value
, &cbData
);
57 if (rc
!= ERROR_SUCCESS
)
59 HeapFree(GetProcessHeap(), 0, Value
);
62 /* NULL-terminate the string */
63 Value
[cbData
/ sizeof(WCHAR
)] = '\0';
70 BOOL
IsConsoleShell(void)
72 HKEY ControlKey
= NULL
;
73 LPWSTR SystemStartOptions
= NULL
;
74 LPWSTR CurrentOption
, NextOption
; /* Pointers into SystemStartOptions */
80 L
"SYSTEM\\CurrentControlSet\\Control",
85 rc
= ReadRegSzKey(ControlKey
, L
"SystemStartOptions", &SystemStartOptions
);
86 if (rc
!= ERROR_SUCCESS
)
89 /* Check for CMDCONS in SystemStartOptions */
90 CurrentOption
= SystemStartOptions
;
93 NextOption
= wcschr(CurrentOption
, L
' ');
96 if (wcsicmp(CurrentOption
, L
"CMDCONS") == 0)
101 CurrentOption
= NextOption
? NextOption
+ 1 : NULL
;
105 if (ControlKey
!= NULL
)
106 RegCloseKey(ControlKey
);
107 HeapFree(GetProcessHeap(), 0, SystemStartOptions
);
112 BOOL
GetShell(WCHAR
*CommandLine
)
116 WCHAR Shell
[MAX_PATH
];
118 BOOL ConsoleShell
= IsConsoleShell();
120 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
121 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
122 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
124 Size
= MAX_PATH
* sizeof(WCHAR
);
125 if(RegQueryValueEx(hKey
,
126 ConsoleShell
? L
"ConsoleShell" : L
"Shell",
130 &Size
) == ERROR_SUCCESS
)
132 if((Type
== REG_SZ
) || (Type
== REG_EXPAND_SZ
))
134 wcscpy(CommandLine
, Shell
);
145 if(GetSystemDirectory(CommandLine
, MAX_PATH
- 8))
146 wcscat(CommandLine
, L
"\\cmd.exe");
148 wcscpy(CommandLine
, L
"cmd.exe");
152 if(GetWindowsDirectory(CommandLine
, MAX_PATH
- 13))
153 wcscat(CommandLine
, L
"\\explorer.exe");
155 wcscpy(CommandLine
, L
"explorer.exe");
163 StartAutoApplications(int clsid
)
165 WCHAR szPath
[MAX_PATH
] = {0};
168 WIN32_FIND_DATAW findData
;
169 SHELLEXECUTEINFOW ExecInfo
;
172 hResult
= SHGetFolderPathW(NULL
, clsid
, NULL
, SHGFP_TYPE_CURRENT
, szPath
);
173 len
= wcslen(szPath
);
174 if (!SUCCEEDED(hResult
) || len
== 0)
179 wcscat(szPath
, L
"\\*");
180 hFind
= FindFirstFileW(szPath
, &findData
);
181 if (hFind
== INVALID_HANDLE_VALUE
)
189 if (!(findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) && (findData
.nFileSizeHigh
|| findData
.nFileSizeLow
))
191 memset(&ExecInfo
, 0x0, sizeof(SHELLEXECUTEINFOW
));
192 ExecInfo
.cbSize
= sizeof(ExecInfo
);
193 ExecInfo
.lpVerb
= L
"open";
194 ExecInfo
.lpFile
= findData
.cFileName
;
195 ExecInfo
.lpDirectory
= szPath
;
196 ShellExecuteExW(&ExecInfo
);
198 }while(FindNextFileW(hFind
, &findData
));
205 void StartShell(void)
208 PROCESS_INFORMATION pi
;
209 WCHAR Shell
[MAX_PATH
];
210 WCHAR ExpandedShell
[MAX_PATH
];
211 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
215 ZeroMemory(&si
, sizeof(STARTUPINFO
));
216 si
.cb
= sizeof(STARTUPINFO
);
217 ZeroMemory(&pi
, sizeof(PROCESS_INFORMATION
));
219 ExpandEnvironmentStrings(Shell
, ExpandedShell
, MAX_PATH
);
221 if(CreateProcess(NULL
,
226 NORMAL_PRIORITY_CLASS
,
232 StartAutoApplications(CSIDL_STARTUP
);
233 StartAutoApplications(CSIDL_COMMON_STARTUP
);
234 WaitForSingleObject(pi
.hProcess
, INFINITE
);
235 CloseHandle(pi
.hProcess
);
236 CloseHandle(pi
.hThread
);
240 LoadString( GetModuleHandle(NULL
), STRING_USERINIT_FAIL
, szMsg
, sizeof(szMsg
) / sizeof(szMsg
[0]));
241 MessageBox(0, szMsg
, NULL
, 0);
246 void SetUserSettings(void)
250 WCHAR szWallpaper
[MAX_PATH
+ 1];
252 if(RegOpenKeyEx(HKEY_CURRENT_USER
,
253 L
"Control Panel\\Desktop",
254 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
256 Size
= sizeof(szWallpaper
);
257 if(RegQueryValueEx(hKey
,
262 &Size
) == ERROR_SUCCESS
265 /* Load and change the wallpaper */
266 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, szWallpaper
, SPIF_SENDCHANGE
);
270 /* remove the wallpaper */
271 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, NULL
, SPIF_SENDCHANGE
);
278 typedef DWORD (WINAPI
*PCMP_REPORT_LOGON
)(DWORD
, DWORD
);
284 PCMP_REPORT_LOGON CMP_Report_LogOn
;
286 hModule
= LoadLibrary(L
"setupapi.dll");
289 CMP_Report_LogOn
= (PCMP_REPORT_LOGON
)GetProcAddress(hModule
, "CMP_Report_LogOn");
290 if (CMP_Report_LogOn
)
291 CMP_Report_LogOn(CMP_MAGIC
, GetCurrentProcessId());
293 FreeLibrary(hModule
);
300 #pragma warning(disable : 4100)
301 #endif /* _MSC_VER */
304 WinMain(HINSTANCE hInst
,
305 HINSTANCE hPrevInstance
,