Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninstall.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS kernel 00003 * Copyright (C) 2003 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 /* 00020 * COPYRIGHT: See COPYING in the top level directory 00021 * PROJECT: ReactOS system libraries 00022 * PURPOSE: System setup 00023 * FILE: dll/win32/syssetup/install.c 00024 * PROGRAMER: Eric Kohl 00025 */ 00026 00027 /* INCLUDES *****************************************************************/ 00028 00029 #include "precomp.h" 00030 00031 #define NDEBUG 00032 #include <debug.h> 00033 00034 DWORD WINAPI 00035 CMP_WaitNoPendingInstallEvents(DWORD dwTimeout); 00036 00037 /* GLOBALS ******************************************************************/ 00038 00039 PSID DomainSid = NULL; 00040 PSID AdminSid = NULL; 00041 00042 HINF hSysSetupInf = INVALID_HANDLE_VALUE; 00043 00044 /* FUNCTIONS ****************************************************************/ 00045 00046 static VOID 00047 FatalError(char *pszFmt,...) 00048 { 00049 char szBuffer[512]; 00050 va_list ap; 00051 00052 va_start(ap, pszFmt); 00053 vsprintf(szBuffer, pszFmt, ap); 00054 va_end(ap); 00055 00056 LogItem(SYSSETUP_SEVERITY_FATAL_ERROR, L"Failed"); 00057 00058 strcat(szBuffer, "\nRebooting now!"); 00059 MessageBoxA(NULL, 00060 szBuffer, 00061 "ReactOS Setup", 00062 MB_OK); 00063 } 00064 00065 static HRESULT 00066 CreateShellLink( 00067 LPCTSTR pszLinkPath, 00068 LPCTSTR pszCmd, 00069 LPCTSTR pszArg, 00070 LPCTSTR pszDir, 00071 LPCTSTR pszIconPath, 00072 int iIconNr, 00073 LPCTSTR pszComment) 00074 { 00075 IShellLink *psl; 00076 IPersistFile *ppf; 00077 #ifndef _UNICODE 00078 WCHAR wszBuf[MAX_PATH]; 00079 #endif /* _UNICODE */ 00080 00081 HRESULT hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl); 00082 00083 if (SUCCEEDED(hr)) 00084 { 00085 hr = psl->lpVtbl->SetPath(psl, pszCmd); 00086 00087 if (pszArg) 00088 { 00089 hr = psl->lpVtbl->SetArguments(psl, pszArg); 00090 } 00091 00092 if (pszDir) 00093 { 00094 hr = psl->lpVtbl->SetWorkingDirectory(psl, pszDir); 00095 } 00096 00097 if (pszIconPath) 00098 { 00099 hr = psl->lpVtbl->SetIconLocation(psl, pszIconPath, iIconNr); 00100 } 00101 00102 if (pszComment) 00103 { 00104 hr = psl->lpVtbl->SetDescription(psl, pszComment); 00105 } 00106 00107 hr = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf); 00108 00109 if (SUCCEEDED(hr)) 00110 { 00111 #ifdef _UNICODE 00112 hr = ppf->lpVtbl->Save(ppf, pszLinkPath, TRUE); 00113 #else /* _UNICODE */ 00114 MultiByteToWideChar(CP_ACP, 0, pszLinkPath, -1, wszBuf, MAX_PATH); 00115 00116 hr = ppf->lpVtbl->Save(ppf, wszBuf, TRUE); 00117 #endif /* _UNICODE */ 00118 00119 ppf->lpVtbl->Release(ppf); 00120 } 00121 00122 psl->lpVtbl->Release(psl); 00123 } 00124 00125 return hr; 00126 } 00127 00128 00129 static BOOL 00130 CreateShortcut( 00131 int csidl, 00132 LPCTSTR pszFolder, 00133 UINT nIdName, 00134 LPCTSTR pszCommand, 00135 UINT nIdTitle, 00136 BOOL bCheckExistence, 00137 INT iIconNr) 00138 { 00139 TCHAR szPath[MAX_PATH]; 00140 TCHAR szExeName[MAX_PATH]; 00141 TCHAR szTitle[256]; 00142 TCHAR szName[256]; 00143 LPTSTR Ptr = szPath; 00144 TCHAR szWorkingDirBuf[MAX_PATH]; 00145 LPTSTR pszWorkingDir = NULL; 00146 LPTSTR lpFilePart; 00147 DWORD dwLen; 00148 00149 if (ExpandEnvironmentStrings(pszCommand, 00150 szPath, 00151 sizeof(szPath) / sizeof(szPath[0])) == 0) 00152 { 00153 _tcscpy(szPath, pszCommand); 00154 } 00155 00156 if (bCheckExistence) 00157 { 00158 if ((_taccess(szPath, 0 )) == -1) 00159 /* Expected error, don't return FALSE */ 00160 return TRUE; 00161 } 00162 00163 dwLen = GetFullPathName(szPath, 00164 sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]), 00165 szWorkingDirBuf, 00166 &lpFilePart); 00167 if (dwLen != 0 && dwLen <= sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0])) 00168 { 00169 /* Since those should only be called with (.exe) files, 00170 lpFilePart has not to be NULL */ 00171 ASSERT(lpFilePart != NULL); 00172 00173 /* Save the file name */ 00174 _tcscpy(szExeName, lpFilePart); 00175 00176 /* We're only interested in the path. Cut the file name off. 00177 Also remove the trailing backslash unless the working directory 00178 is only going to be a drive, ie. C:\ */ 00179 *(lpFilePart--) = _T('\0'); 00180 if (!(lpFilePart - szWorkingDirBuf == 2 && szWorkingDirBuf[1] == _T(':') && 00181 szWorkingDirBuf[2] == _T('\\'))) 00182 { 00183 *lpFilePart = _T('\0'); 00184 } 00185 00186 pszWorkingDir = szWorkingDirBuf; 00187 } 00188 00189 00190 if (!SHGetSpecialFolderPath(0, szPath, csidl, TRUE)) 00191 return FALSE; 00192 00193 if (pszFolder) 00194 { 00195 Ptr = PathAddBackslash(Ptr); 00196 _tcscpy(Ptr, pszFolder); 00197 } 00198 00199 Ptr = PathAddBackslash(Ptr); 00200 00201 if (!LoadString(hDllInstance, nIdName, szName, sizeof(szName)/sizeof(szName[0]))) 00202 return FALSE; 00203 _tcscpy(Ptr, szName); 00204 00205 if (!LoadString(hDllInstance, nIdTitle, szTitle, sizeof(szTitle)/sizeof(szTitle[0]))) 00206 return FALSE; 00207 00208 // FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it 00209 return SUCCEEDED(CreateShellLink(szPath, szExeName, _T(""), pszWorkingDir, szExeName, iIconNr, szTitle)); 00210 } 00211 00212 static BOOL 00213 CreateShortcutFolder(int csidl, UINT nID, LPTSTR pszName, int cchNameLen) 00214 { 00215 TCHAR szPath[MAX_PATH]; 00216 LPTSTR p; 00217 00218 if (!SHGetSpecialFolderPath(0, szPath, csidl, TRUE)) 00219 return FALSE; 00220 00221 if (!LoadString(hDllInstance, nID, pszName, cchNameLen)) 00222 return FALSE; 00223 00224 p = PathAddBackslash(szPath); 00225 _tcscpy(p, pszName); 00226 00227 return CreateDirectory(szPath, NULL) || GetLastError()==ERROR_ALREADY_EXISTS; 00228 } 00229 00230 static BOOL 00231 CreateRandomSid( 00232 OUT PSID *Sid) 00233 { 00234 SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; 00235 LARGE_INTEGER SystemTime; 00236 PULONG Seed; 00237 NTSTATUS Status; 00238 00239 NtQuerySystemTime(&SystemTime); 00240 Seed = &SystemTime.u.LowPart; 00241 00242 Status = RtlAllocateAndInitializeSid( 00243 &SystemAuthority, 00244 4, 00245 SECURITY_NT_NON_UNIQUE, 00246 RtlUniform(Seed), 00247 RtlUniform(Seed), 00248 RtlUniform(Seed), 00249 SECURITY_NULL_RID, 00250 SECURITY_NULL_RID, 00251 SECURITY_NULL_RID, 00252 SECURITY_NULL_RID, 00253 Sid); 00254 return NT_SUCCESS(Status); 00255 } 00256 00257 static VOID 00258 AppendRidToSid( 00259 OUT PSID *Dst, 00260 IN PSID Src, 00261 IN ULONG NewRid) 00262 { 00263 ULONG Rid[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 00264 UCHAR RidCount; 00265 ULONG i; 00266 00267 RidCount = *RtlSubAuthorityCountSid (Src); 00268 00269 for (i = 0; i < RidCount; i++) 00270 Rid[i] = *RtlSubAuthoritySid (Src, i); 00271 00272 if (RidCount < 8) 00273 { 00274 Rid[RidCount] = NewRid; 00275 RidCount++; 00276 } 00277 00278 RtlAllocateAndInitializeSid( 00279 RtlIdentifierAuthoritySid(Src), 00280 RidCount, 00281 Rid[0], 00282 Rid[1], 00283 Rid[2], 00284 Rid[3], 00285 Rid[4], 00286 Rid[5], 00287 Rid[6], 00288 Rid[7], 00289 Dst); 00290 } 00291 00292 static VOID 00293 CreateTempDir( 00294 IN LPCWSTR VarName) 00295 { 00296 WCHAR szTempDir[MAX_PATH]; 00297 WCHAR szBuffer[MAX_PATH]; 00298 DWORD dwLength; 00299 HKEY hKey; 00300 00301 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00302 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", 00303 0, 00304 KEY_QUERY_VALUE, 00305 &hKey) != ERROR_SUCCESS) 00306 { 00307 FatalError("Error: %lu\n", GetLastError()); 00308 return; 00309 } 00310 00311 /* Get temp dir */ 00312 dwLength = MAX_PATH * sizeof(WCHAR); 00313 if (RegQueryValueExW(hKey, 00314 VarName, 00315 NULL, 00316 NULL, 00317 (LPBYTE)szBuffer, 00318 &dwLength) != ERROR_SUCCESS) 00319 { 00320 FatalError("Error: %lu\n", GetLastError()); 00321 goto cleanup; 00322 } 00323 00324 /* Expand it */ 00325 if (!ExpandEnvironmentStringsW(szBuffer, 00326 szTempDir, 00327 MAX_PATH)) 00328 { 00329 FatalError("Error: %lu\n", GetLastError()); 00330 goto cleanup; 00331 } 00332 00333 /* Create profiles directory */ 00334 if (!CreateDirectoryW(szTempDir, NULL)) 00335 { 00336 if (GetLastError() != ERROR_ALREADY_EXISTS) 00337 { 00338 FatalError("Error: %lu\n", GetLastError()); 00339 goto cleanup; 00340 } 00341 } 00342 00343 cleanup: 00344 RegCloseKey(hKey); 00345 } 00346 00347 static BOOL 00348 InstallSysSetupInfDevices(VOID) 00349 { 00350 INFCONTEXT InfContext; 00351 WCHAR szLineBuffer[256]; 00352 DWORD dwLineLength; 00353 00354 if (!SetupFindFirstLineW(hSysSetupInf, 00355 L"DeviceInfsToInstall", 00356 NULL, 00357 &InfContext)) 00358 { 00359 return FALSE; 00360 } 00361 00362 do 00363 { 00364 if (!SetupGetStringFieldW(&InfContext, 00365 0, 00366 szLineBuffer, 00367 sizeof(szLineBuffer)/sizeof(szLineBuffer[0]), 00368 &dwLineLength)) 00369 { 00370 return FALSE; 00371 } 00372 00373 if (!SetupDiInstallClassW(NULL, szLineBuffer, DI_QUIETINSTALL, NULL)) 00374 { 00375 return FALSE; 00376 } 00377 } 00378 while (SetupFindNextLine(&InfContext, &InfContext)); 00379 00380 return TRUE; 00381 } 00382 00383 static BOOL 00384 InstallSysSetupInfComponents(VOID) 00385 { 00386 INFCONTEXT InfContext; 00387 WCHAR szNameBuffer[256]; 00388 WCHAR szSectionBuffer[256]; 00389 HINF hComponentInf = INVALID_HANDLE_VALUE; 00390 00391 if (!SetupFindFirstLineW(hSysSetupInf, 00392 L"Infs.Always", 00393 NULL, 00394 &InfContext)) 00395 { 00396 DPRINT("No Inf.Always section found\n"); 00397 } 00398 else 00399 { 00400 do 00401 { 00402 if (!SetupGetStringFieldW(&InfContext, 00403 1, // Get the component name 00404 szNameBuffer, 00405 sizeof(szNameBuffer)/sizeof(szNameBuffer[0]), 00406 NULL)) 00407 { 00408 FatalError("Error while trying to get component name \n"); 00409 return FALSE; 00410 } 00411 00412 if (!SetupGetStringFieldW(&InfContext, 00413 2, // Get the component install section 00414 szSectionBuffer, 00415 sizeof(szSectionBuffer)/sizeof(szSectionBuffer[0]), 00416 NULL)) 00417 { 00418 FatalError("Error while trying to get component install section \n"); 00419 return FALSE; 00420 } 00421 00422 DPRINT("Trying to execute install section '%S' from '%S' \n", szSectionBuffer, szNameBuffer); 00423 00424 hComponentInf = SetupOpenInfFileW(szNameBuffer, 00425 NULL, 00426 INF_STYLE_WIN4, 00427 NULL); 00428 00429 if (hComponentInf == INVALID_HANDLE_VALUE) 00430 { 00431 FatalError("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", szNameBuffer, GetLastError()); 00432 return FALSE; 00433 } 00434 00435 if (!SetupInstallFromInfSectionW(NULL, 00436 hComponentInf, 00437 szSectionBuffer, 00438 SPINST_ALL, 00439 NULL, 00440 NULL, 00441 SP_COPY_NEWER, 00442 SetupDefaultQueueCallbackW, 00443 NULL, 00444 NULL, 00445 NULL)) 00446 { 00447 FatalError("Error while trying to install : %S (Error: %lu)\n", szNameBuffer, GetLastError()); 00448 SetupCloseInfFile(hComponentInf); 00449 return FALSE; 00450 } 00451 00452 SetupCloseInfFile(hComponentInf); 00453 } 00454 while (SetupFindNextLine(&InfContext, &InfContext)); 00455 } 00456 00457 return TRUE; 00458 } 00459 00460 static BOOL 00461 EnableUserModePnpManager(VOID) 00462 { 00463 SC_HANDLE hSCManager = NULL; 00464 SC_HANDLE hService = NULL; 00465 BOOL bRet = FALSE; 00466 00467 hSCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE); 00468 if (hSCManager == NULL) 00469 { 00470 DPRINT1("Unable to open the service control manager.\n"); 00471 DPRINT1("Last Error %d\n", GetLastError()); 00472 goto cleanup; 00473 } 00474 00475 hService = OpenServiceW(hSCManager, 00476 L"PlugPlay", 00477 SERVICE_CHANGE_CONFIG | SERVICE_START); 00478 if (hService == NULL) 00479 { 00480 DPRINT1("Unable to open PlugPlay service\n"); 00481 goto cleanup; 00482 } 00483 00484 bRet = ChangeServiceConfigW(hService, 00485 SERVICE_NO_CHANGE, 00486 SERVICE_AUTO_START, 00487 SERVICE_NO_CHANGE, 00488 NULL, NULL, NULL, 00489 NULL, NULL, NULL, NULL); 00490 if (!bRet) 00491 { 00492 DPRINT1("Unable to change the service configuration\n"); 00493 goto cleanup; 00494 } 00495 00496 bRet = StartServiceW(hService, 0, NULL); 00497 if (!bRet && (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING)) 00498 { 00499 DPRINT1("Unable to start service\n"); 00500 goto cleanup; 00501 } 00502 00503 bRet = TRUE; 00504 00505 cleanup: 00506 if (hSCManager != NULL) 00507 CloseServiceHandle(hSCManager); 00508 if (hService != NULL) 00509 CloseServiceHandle(hService); 00510 return bRet; 00511 } 00512 00513 static INT_PTR CALLBACK 00514 StatusMessageWindowProc( 00515 IN HWND hwndDlg, 00516 IN UINT uMsg, 00517 IN WPARAM wParam, 00518 IN LPARAM lParam) 00519 { 00520 UNREFERENCED_PARAMETER(wParam); 00521 00522 switch (uMsg) 00523 { 00524 case WM_INITDIALOG: 00525 { 00526 WCHAR szMsg[256]; 00527 00528 if (!LoadStringW(hDllInstance, IDS_STATUS_INSTALL_DEV, szMsg, sizeof(szMsg)/sizeof(szMsg[0]))) 00529 return FALSE; 00530 SetDlgItemTextW(hwndDlg, IDC_STATUSLABEL, szMsg); 00531 return TRUE; 00532 } 00533 } 00534 return FALSE; 00535 } 00536 00537 static DWORD WINAPI 00538 ShowStatusMessageThread( 00539 IN LPVOID lpParameter) 00540 { 00541 HWND *phWnd = (HWND *)lpParameter; 00542 HWND hWnd; 00543 MSG Msg; 00544 00545 hWnd = CreateDialogParam( 00546 hDllInstance, 00547 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG), 00548 GetDesktopWindow(), 00549 StatusMessageWindowProc, 00550 (LPARAM)NULL); 00551 if (!hWnd) 00552 return 0; 00553 *phWnd = hWnd; 00554 00555 ShowWindow(hWnd, SW_SHOW); 00556 00557 /* Message loop for the Status window */ 00558 while (GetMessage(&Msg, NULL, 0, 0)) 00559 { 00560 TranslateMessage(&Msg); 00561 DispatchMessage(&Msg); 00562 } 00563 00564 return 0; 00565 } 00566 00567 static LONG 00568 ReadRegSzKey( 00569 IN HKEY hKey, 00570 IN LPCWSTR pszKey, 00571 OUT LPWSTR* pValue) 00572 { 00573 LONG rc; 00574 DWORD dwType; 00575 DWORD cbData = 0; 00576 LPWSTR pwszValue; 00577 00578 if (!pValue) 00579 return ERROR_INVALID_PARAMETER; 00580 00581 *pValue = NULL; 00582 rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData); 00583 if (rc != ERROR_SUCCESS) 00584 return rc; 00585 if (dwType != REG_SZ) 00586 return ERROR_FILE_NOT_FOUND; 00587 pwszValue = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR)); 00588 if (!pwszValue) 00589 return ERROR_NOT_ENOUGH_MEMORY; 00590 rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)pwszValue, &cbData); 00591 if (rc != ERROR_SUCCESS) 00592 { 00593 HeapFree(GetProcessHeap(), 0, pwszValue); 00594 return rc; 00595 } 00596 /* NULL-terminate the string */ 00597 pwszValue[cbData / sizeof(WCHAR)] = '\0'; 00598 00599 *pValue = pwszValue; 00600 return ERROR_SUCCESS; 00601 } 00602 00603 static BOOL 00604 IsConsoleBoot(VOID) 00605 { 00606 HKEY hControlKey = NULL; 00607 LPWSTR pwszSystemStartOptions = NULL; 00608 LPWSTR pwszCurrentOption, pwszNextOption; /* Pointers into SystemStartOptions */ 00609 BOOL bConsoleBoot = FALSE; 00610 LONG rc; 00611 00612 rc = RegOpenKeyExW( 00613 HKEY_LOCAL_MACHINE, 00614 L"SYSTEM\\CurrentControlSet\\Control", 00615 0, 00616 KEY_QUERY_VALUE, 00617 &hControlKey); 00618 if (rc != ERROR_SUCCESS) 00619 goto cleanup; 00620 00621 rc = ReadRegSzKey(hControlKey, L"SystemStartOptions", &pwszSystemStartOptions); 00622 if (rc != ERROR_SUCCESS) 00623 goto cleanup; 00624 00625 /* Check for CMDCONS in SystemStartOptions */ 00626 pwszCurrentOption = pwszSystemStartOptions; 00627 while (pwszCurrentOption) 00628 { 00629 pwszNextOption = wcschr(pwszCurrentOption, L' '); 00630 if (pwszNextOption) 00631 *pwszNextOption = L'\0'; 00632 if (wcsicmp(pwszCurrentOption, L"CONSOLE") == 0) 00633 { 00634 DPRINT("Found %S. Switching to console boot\n", pwszCurrentOption); 00635 bConsoleBoot = TRUE; 00636 goto cleanup; 00637 } 00638 pwszCurrentOption = pwszNextOption ? pwszNextOption + 1 : NULL; 00639 } 00640 00641 cleanup: 00642 if (hControlKey != NULL) 00643 RegCloseKey(hControlKey); 00644 if (pwszSystemStartOptions) 00645 HeapFree(GetProcessHeap(), 0, pwszSystemStartOptions); 00646 return bConsoleBoot; 00647 } 00648 00649 static BOOL 00650 CommonInstall(VOID) 00651 { 00652 HWND hWnd = NULL; 00653 00654 hSysSetupInf = SetupOpenInfFileW( 00655 L"syssetup.inf", 00656 NULL, 00657 INF_STYLE_WIN4, 00658 NULL); 00659 if (hSysSetupInf == INVALID_HANDLE_VALUE) 00660 { 00661 FatalError("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError()); 00662 return FALSE; 00663 } 00664 00665 if (!InstallSysSetupInfDevices()) 00666 { 00667 FatalError("InstallSysSetupInfDevices() failed!\n"); 00668 goto error; 00669 } 00670 00671 if(!InstallSysSetupInfComponents()) 00672 { 00673 FatalError("InstallSysSetupInfComponents() failed!\n"); 00674 goto error; 00675 } 00676 00677 if (!IsConsoleBoot()) 00678 { 00679 HANDLE hThread; 00680 00681 hThread = CreateThread( 00682 NULL, 00683 0, 00684 ShowStatusMessageThread, 00685 (LPVOID)&hWnd, 00686 0, 00687 NULL); 00688 00689 if (hThread) 00690 CloseHandle(hThread); 00691 } 00692 00693 if (!EnableUserModePnpManager()) 00694 { 00695 FatalError("EnableUserModePnpManager() failed!\n"); 00696 goto error; 00697 } 00698 00699 if (CMP_WaitNoPendingInstallEvents(INFINITE) != WAIT_OBJECT_0) 00700 { 00701 FatalError("CMP_WaitNoPendingInstallEvents() failed!\n"); 00702 goto error; 00703 } 00704 00705 EndDialog(hWnd, 0); 00706 return TRUE; 00707 00708 error: 00709 if (hWnd) 00710 EndDialog(hWnd, 0); 00711 SetupCloseInfFile(hSysSetupInf); 00712 return FALSE; 00713 } 00714 00715 DWORD WINAPI 00716 InstallLiveCD(IN HINSTANCE hInstance) 00717 { 00718 STARTUPINFOW StartupInfo; 00719 PROCESS_INFORMATION ProcessInformation; 00720 BOOL bRes; 00721 00722 if (!CommonInstall()) 00723 goto error; 00724 00725 /* Register components */ 00726 _SEH2_TRY 00727 { 00728 if (!SetupInstallFromInfSectionW(NULL, 00729 hSysSetupInf, L"RegistrationPhase2", 00730 SPINST_ALL, 00731 0, NULL, 0, NULL, NULL, NULL, NULL)) 00732 { 00733 DPRINT1("SetupInstallFromInfSectionW failed!\n"); 00734 } 00735 } 00736 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 00737 { 00738 DPRINT1("Catching exception\n"); 00739 } 00740 _SEH2_END; 00741 00742 SetupCloseInfFile(hSysSetupInf); 00743 00744 /* Run the shell */ 00745 StartupInfo.cb = sizeof(STARTUPINFOW); 00746 StartupInfo.lpReserved = NULL; 00747 StartupInfo.lpDesktop = NULL; 00748 StartupInfo.lpTitle = NULL; 00749 StartupInfo.dwFlags = 0; 00750 StartupInfo.cbReserved2 = 0; 00751 StartupInfo.lpReserved2 = 0; 00752 bRes = CreateProcessW( 00753 L"userinit.exe", 00754 NULL, 00755 NULL, 00756 NULL, 00757 FALSE, 00758 0, 00759 NULL, 00760 NULL, 00761 &StartupInfo, 00762 &ProcessInformation); 00763 if (!bRes) 00764 goto error; 00765 00766 CloseHandle(ProcessInformation.hThread); 00767 CloseHandle(ProcessInformation.hProcess); 00768 00769 return 0; 00770 00771 error: 00772 MessageBoxW( 00773 NULL, 00774 L"Failed to load LiveCD! You can shutdown your computer, or press ENTER to reboot.", 00775 L"ReactOS LiveCD", 00776 MB_OK); 00777 return 0; 00778 } 00779 00780 00781 static BOOL 00782 CreateShortcuts(VOID) 00783 { 00784 TCHAR szFolder[256]; 00785 00786 CoInitialize(NULL); 00787 00788 /* Create desktop shortcuts */ 00789 CreateShortcut(CSIDL_DESKTOP, NULL, IDS_SHORT_CMD, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD, TRUE, 0); 00790 00791 /* Create program startmenu shortcuts */ 00792 CreateShortcut(CSIDL_PROGRAMS, NULL, IDS_SHORT_EXPLORER, _T("%SystemRoot%\\explorer.exe"), IDS_CMT_EXPLORER, TRUE, 1); 00793 CreateShortcut(CSIDL_PROGRAMS, NULL, IDS_SHORT_DOWNLOADER, _T("%SystemRoot%\\system32\\rapps.exe"), IDS_CMT_DOWNLOADER, TRUE, 0); 00794 00795 /* Create administrative tools startmenu shortcuts */ 00796 CreateShortcut(CSIDL_COMMON_ADMINTOOLS, NULL, IDS_SHORT_SERVICE, _T("%SystemRoot%\\system32\\servman.exe"), IDS_CMT_SERVMAN, TRUE, 0); 00797 CreateShortcut(CSIDL_COMMON_ADMINTOOLS, NULL, IDS_SHORT_DEVICE, _T("%SystemRoot%\\system32\\devmgmt.exe"), IDS_CMT_DEVMGMT, TRUE, 0); 00798 CreateShortcut(CSIDL_COMMON_ADMINTOOLS, NULL, IDS_SHORT_EVENTVIEW, _T("%SystemRoot%\\system32\\eventvwr.exe"), IDS_CMT_EVENTVIEW, TRUE, 0); 00799 CreateShortcut(CSIDL_COMMON_ADMINTOOLS, NULL, IDS_SHORT_MSCONFIG, _T("%SystemRoot%\\system32\\msconfig.exe"), IDS_CMT_MSCONFIG, TRUE, 0); 00800 00801 /* Create and fill Accessories subfolder */ 00802 if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_ACCESSORIES, szFolder, sizeof(szFolder)/sizeof(szFolder[0]))) 00803 { 00804 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_CALC, _T("%SystemRoot%\\system32\\calc.exe"), IDS_CMT_CALC, TRUE, 0); 00805 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_CMD, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD, TRUE, 0); 00806 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_NOTEPAD, _T("%SystemRoot%\\system32\\notepad.exe"), IDS_CMT_NOTEPAD, TRUE, 0); 00807 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_RDESKTOP, _T("%SystemRoot%\\system32\\mstsc.exe"), IDS_CMT_RDESKTOP, TRUE, 0); 00808 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_SNAP, _T("%SystemRoot%\\system32\\screenshot.exe"), IDS_CMT_SCREENSHOT, TRUE, 0); 00809 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_WORDPAD, _T("%SystemRoot%\\system32\\wordpad.exe"), IDS_CMT_WORDPAD, TRUE, 0); 00810 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_PAINT, _T("%SystemRoot%\\system32\\mspaint.exe"), IDS_CMT_PAINT, TRUE, 0); 00811 } 00812 00813 /* Create System Tools subfolder and fill if the exe is available */ 00814 if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_SYS_TOOLS, szFolder, sizeof(szFolder)/sizeof(szFolder[0]))) 00815 { 00816 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_CHARMAP, _T("%SystemRoot%\\system32\\charmap.exe"), IDS_CMT_CHARMAP, TRUE, 0); 00817 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_KBSWITCH, _T("%SystemRoot%\\system32\\kbswitch.exe"), IDS_CMT_KBSWITCH, TRUE, 0); 00818 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_REGEDIT, _T("%SystemRoot%\\regedit.exe"), IDS_CMT_REGEDIT, TRUE, 0); 00819 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_DXDIAG, _T("%SystemRoot%\\system32\\dxdiag.exe"), IDS_CMT_DXDIAG, TRUE, 0); 00820 } 00821 00822 /* Create Accessibility subfolder and fill if the exe is available */ 00823 if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_SYS_ACCESSIBILITY, szFolder, sizeof(szFolder)/sizeof(szFolder[0]))) 00824 { 00825 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_MAGNIFY, _T("%SystemRoot%\\system32\\magnify.exe"), IDS_CMT_MAGNIFY, TRUE, 0); 00826 } 00827 00828 /* Create Entertainment subfolder and fill if the exe is available */ 00829 if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_SYS_ENTERTAINMENT, szFolder, sizeof(szFolder)/sizeof(szFolder[0]))) 00830 { 00831 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_MPLAY32, _T("%SystemRoot%\\system32\\mplay32.exe"), IDS_CMT_MPLAY32, TRUE, 0); 00832 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_SNDVOL32, _T("%SystemRoot%\\system32\\sndvol32.exe"), IDS_CMT_SNDVOL32, TRUE, 0); 00833 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_SNDREC32, _T("%SystemRoot%\\system32\\sndrec32.exe"), IDS_CMT_SNDREC32, TRUE, 0); 00834 } 00835 00836 /* Create Games subfolder and fill if the exe is available */ 00837 if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_GAMES, szFolder, sizeof(szFolder)/sizeof(szFolder[0]))) 00838 { 00839 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_SOLITAIRE, _T("%SystemRoot%\\system32\\sol.exe"), IDS_CMT_SOLITAIRE, TRUE, 0); 00840 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_WINEMINE, _T("%SystemRoot%\\system32\\winmine.exe"), IDS_CMT_WINEMINE, TRUE, 0); 00841 CreateShortcut(CSIDL_PROGRAMS, szFolder, IDS_SHORT_SPIDER, _T("%SystemRoot%\\system32\\spider.exe"), IDS_CMT_SPIDER, TRUE, 0); 00842 } 00843 00844 CoUninitialize(); 00845 00846 return TRUE; 00847 } 00848 00849 static BOOL 00850 SetSetupType(DWORD dwSetupType) 00851 { 00852 DWORD dwError; 00853 HKEY hKey; 00854 00855 dwError = RegOpenKeyExW( 00856 HKEY_LOCAL_MACHINE, 00857 L"SYSTEM\\Setup", 00858 0, 00859 KEY_SET_VALUE, 00860 &hKey); 00861 if (dwError != ERROR_SUCCESS) 00862 return FALSE; 00863 00864 dwError = RegSetValueExW( 00865 hKey, 00866 L"SetupType", 00867 0, 00868 REG_DWORD, 00869 (LPBYTE)&dwSetupType, 00870 sizeof(DWORD)); 00871 RegCloseKey(hKey); 00872 if (dwError != ERROR_SUCCESS) 00873 return FALSE; 00874 00875 return TRUE; 00876 } 00877 00878 DWORD WINAPI 00879 InstallReactOS(HINSTANCE hInstance) 00880 { 00881 TCHAR szBuffer[MAX_PATH]; 00882 DWORD LastError; 00883 HANDLE token; 00884 TOKEN_PRIVILEGES privs; 00885 HKEY hKey; 00886 00887 InitializeSetupActionLog(FALSE); 00888 LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS"); 00889 00890 if (!InitializeProfiles()) 00891 { 00892 FatalError("InitializeProfiles() failed"); 00893 return 0; 00894 } 00895 00896 /* Create the semi-random Domain-SID */ 00897 if (!CreateRandomSid(&DomainSid)) 00898 { 00899 FatalError("Domain-SID creation failed!"); 00900 return 0; 00901 } 00902 00903 /* Set the Domain SID (aka Computer SID) */ 00904 if (SetAccountDomain(NULL, DomainSid) != STATUS_SUCCESS) 00905 { 00906 FatalError("SetAccountDomain() failed!"); 00907 RtlFreeSid(DomainSid); 00908 return 0; 00909 } 00910 00911 /* Append the Admin-RID */ 00912 AppendRidToSid(&AdminSid, DomainSid, DOMAIN_USER_RID_ADMIN); 00913 00914 CreateTempDir(L"TEMP"); 00915 CreateTempDir(L"TMP"); 00916 00917 if (GetWindowsDirectory(szBuffer, sizeof(szBuffer) / sizeof(TCHAR))) 00918 { 00919 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00920 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 00921 0, 00922 KEY_WRITE, 00923 &hKey) == ERROR_SUCCESS) 00924 { 00925 RegSetValueExW(hKey, 00926 L"PathName", 00927 0, 00928 REG_SZ, 00929 (LPBYTE)szBuffer, 00930 (wcslen(szBuffer) + 1) * sizeof(WCHAR)); 00931 00932 RegSetValueExW(hKey, 00933 L"SystemRoot", 00934 0, 00935 REG_SZ, 00936 (LPBYTE)szBuffer, 00937 (wcslen(szBuffer) + 1) * sizeof(WCHAR)); 00938 00939 RegCloseKey(hKey); 00940 } 00941 00942 PathAddBackslash(szBuffer); 00943 _tcscat(szBuffer, _T("system")); 00944 CreateDirectory(szBuffer, NULL); 00945 } 00946 00947 if (!CommonInstall()) 00948 return 0; 00949 00950 InstallWizard(); 00951 00952 InstallSecurity(); 00953 00954 /* Create the Administrator account */ 00955 if (!SamCreateUser(L"Administrator", L"", AdminSid)) 00956 { 00957 /* Check what the error was. 00958 * If the Admin Account already exists, then it means Setup 00959 * wasn't allowed to finish properly. Instead of rebooting 00960 * and not completing it, let it restart instead 00961 */ 00962 LastError = GetLastError(); 00963 if (LastError != ERROR_USER_EXISTS) 00964 { 00965 FatalError("SamCreateUser() failed!"); 00966 RtlFreeSid(AdminSid); 00967 RtlFreeSid(DomainSid); 00968 return 0; 00969 } 00970 } 00971 00972 RtlFreeSid(AdminSid); 00973 RtlFreeSid(DomainSid); 00974 00975 if (!CreateShortcuts()) 00976 { 00977 FatalError("CreateShortcuts() failed"); 00978 return 0; 00979 } 00980 00981 /* ROS HACK, as long as NtUnloadKey is not implemented */ 00982 { 00983 NTSTATUS Status = NtUnloadKey(NULL); 00984 if (Status == STATUS_NOT_IMPLEMENTED) 00985 { 00986 /* Create the Administrator profile */ 00987 PROFILEINFOW ProfileInfo; 00988 HANDLE hToken; 00989 BOOL ret; 00990 00991 ret = LogonUserW(L"Administrator", L"", L"", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &hToken); 00992 if (!ret) 00993 { 00994 FatalError("LogonUserW() failed!"); 00995 return 0; 00996 } 00997 ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW)); 00998 ProfileInfo.dwSize = sizeof(PROFILEINFOW); 00999 ProfileInfo.lpUserName = L"Administrator"; 01000 ProfileInfo.dwFlags = PI_NOUI; 01001 LoadUserProfileW(hToken, &ProfileInfo); 01002 CloseHandle(hToken); 01003 } 01004 else 01005 { 01006 DPRINT1("ROS HACK not needed anymore. Please remove it\n"); 01007 } 01008 } 01009 /* END OF ROS HACK */ 01010 01011 SetupCloseInfFile(hSysSetupInf); 01012 SetSetupType(0); 01013 01014 LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done"); 01015 TerminateSetupActionLog(); 01016 01017 /* Get shutdown privilege */ 01018 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) 01019 { 01020 FatalError("OpenProcessToken() failed!"); 01021 return 0; 01022 } 01023 if (!LookupPrivilegeValue( 01024 NULL, 01025 SE_SHUTDOWN_NAME, 01026 &privs.Privileges[0].Luid)) 01027 { 01028 FatalError("LookupPrivilegeValue() failed!"); 01029 return 0; 01030 } 01031 privs.PrivilegeCount = 1; 01032 privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 01033 if (AdjustTokenPrivileges( 01034 token, 01035 FALSE, 01036 &privs, 01037 0, 01038 (PTOKEN_PRIVILEGES)NULL, 01039 NULL) == 0) 01040 { 01041 FatalError("AdjustTokenPrivileges() failed!"); 01042 return 0; 01043 } 01044 01045 ExitWindowsEx(EWX_REBOOT, 0); 01046 return 0; 01047 } 01048 01049 01050 /* 01051 * @unimplemented 01052 */ 01053 DWORD WINAPI 01054 SetupChangeFontSize( 01055 IN HANDLE hWnd, 01056 IN LPCWSTR lpszFontSize) 01057 { 01058 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 01059 return FALSE; 01060 } 01061 01062 /* 01063 * @unimplemented 01064 */ 01065 DWORD WINAPI 01066 SetupChangeLocaleEx(HWND hWnd, 01067 LCID Lcid, 01068 LPCWSTR lpSrcRootPath, 01069 char Unknown, 01070 DWORD dwUnused1, 01071 DWORD dwUnused2) 01072 { 01073 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 01074 return FALSE; 01075 } 01076 01077 /* 01078 * @implemented 01079 */ 01080 DWORD WINAPI 01081 SetupChangeLocale(HWND hWnd, LCID Lcid) 01082 { 01083 return SetupChangeLocaleEx(hWnd, Lcid, NULL, 0, 0, 0); 01084 } Generated on Sun May 27 2012 04:19:20 for ReactOS by
1.7.6.1
|