3 * Copyright (C) 2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * PURPOSE: System setup
23 * FILE: dll/win32/syssetup/install.c
24 * PROGRAMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
35 CMP_WaitNoPendingInstallEvents(DWORD dwTimeout
);
37 /* GLOBALS ******************************************************************/
39 PSID DomainSid
= NULL
;
42 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
44 /* FUNCTIONS ****************************************************************/
47 FatalError(char *pszFmt
,...)
53 vsprintf(szBuffer
, pszFmt
, ap
);
56 LogItem(SYSSETUP_SEVERITY_FATAL_ERROR
, L
"Failed");
58 strcat(szBuffer
, "\nRebooting now!");
78 WCHAR wszBuf
[MAX_PATH
];
81 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
85 hr
= psl
->lpVtbl
->SetPath(psl
, pszCmd
);
89 hr
= psl
->lpVtbl
->SetArguments(psl
, pszArg
);
94 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, pszDir
);
99 hr
= psl
->lpVtbl
->SetIconLocation(psl
, pszIconPath
, iIconNr
);
104 hr
= psl
->lpVtbl
->SetDescription(psl
, pszComment
);
107 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
112 hr
= ppf
->lpVtbl
->Save(ppf
, pszLinkPath
, TRUE
);
114 MultiByteToWideChar(CP_ACP
, 0, pszLinkPath
, -1, wszBuf
, MAX_PATH
);
116 hr
= ppf
->lpVtbl
->Save(ppf
, wszBuf
, TRUE
);
117 #endif /* _UNICODE */
119 ppf
->lpVtbl
->Release(ppf
);
122 psl
->lpVtbl
->Release(psl
);
136 BOOL bCheckExistence
,
139 TCHAR szPath
[MAX_PATH
];
140 TCHAR szExeName
[MAX_PATH
];
144 TCHAR szWorkingDirBuf
[MAX_PATH
];
145 LPTSTR pszWorkingDir
= NULL
;
149 if (ExpandEnvironmentStrings(pszCommand
,
151 sizeof(szPath
) / sizeof(szPath
[0])) == 0)
153 _tcscpy(szPath
, pszCommand
);
158 if ((_taccess(szPath
, 0 )) == -1)
159 /* Expected error, don't return FALSE */
163 dwLen
= GetFullPathName(szPath
,
164 sizeof(szWorkingDirBuf
) / sizeof(szWorkingDirBuf
[0]),
167 if (dwLen
!= 0 && dwLen
<= sizeof(szWorkingDirBuf
) / sizeof(szWorkingDirBuf
[0]))
169 /* Since those should only be called with (.exe) files,
170 lpFilePart has not to be NULL */
171 ASSERT(lpFilePart
!= NULL
);
173 /* Save the file name */
174 _tcscpy(szExeName
, lpFilePart
);
176 /* We're only interested in the path. Cut the file name off.
177 Also remove the trailing backslash unless the working directory
178 is only going to be a drive, ie. C:\ */
179 *(lpFilePart
--) = _T('\0');
180 if (!(lpFilePart
- szWorkingDirBuf
== 2 && szWorkingDirBuf
[1] == _T(':') &&
181 szWorkingDirBuf
[2] == _T('\\')))
183 *lpFilePart
= _T('\0');
186 pszWorkingDir
= szWorkingDirBuf
;
190 if (!SHGetSpecialFolderPath(0, szPath
, csidl
, TRUE
))
195 Ptr
= PathAddBackslash(Ptr
);
196 _tcscpy(Ptr
, pszFolder
);
199 Ptr
= PathAddBackslash(Ptr
);
201 if (!LoadString(hDllInstance
, nIdName
, szName
, sizeof(szName
)/sizeof(szName
[0])))
203 _tcscpy(Ptr
, szName
);
205 if (!LoadString(hDllInstance
, nIdTitle
, szTitle
, sizeof(szTitle
)/sizeof(szTitle
[0])))
208 // FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
209 return SUCCEEDED(CreateShellLink(szPath
, szExeName
, _T(""), pszWorkingDir
, szExeName
, iIconNr
, szTitle
));
213 CreateShortcutFolder(int csidl
, UINT nID
, LPTSTR pszName
, int cchNameLen
)
215 TCHAR szPath
[MAX_PATH
];
218 if (!SHGetSpecialFolderPath(0, szPath
, csidl
, TRUE
))
221 if (!LoadString(hDllInstance
, nID
, pszName
, cchNameLen
))
224 p
= PathAddBackslash(szPath
);
227 return CreateDirectory(szPath
, NULL
) || GetLastError()==ERROR_ALREADY_EXISTS
;
234 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
235 LARGE_INTEGER SystemTime
;
239 NtQuerySystemTime(&SystemTime
);
240 Seed
= &SystemTime
.u
.LowPart
;
242 Status
= RtlAllocateAndInitializeSid(
245 SECURITY_NT_NON_UNIQUE
,
254 return NT_SUCCESS(Status
);
263 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
267 RidCount
= *RtlSubAuthorityCountSid (Src
);
269 for (i
= 0; i
< RidCount
; i
++)
270 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
274 Rid
[RidCount
] = NewRid
;
278 RtlAllocateAndInitializeSid(
279 RtlIdentifierAuthoritySid(Src
),
296 WCHAR szTempDir
[MAX_PATH
];
297 WCHAR szBuffer
[MAX_PATH
];
301 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
302 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
305 &hKey
) != ERROR_SUCCESS
)
307 FatalError("Error: %lu\n", GetLastError());
312 dwLength
= MAX_PATH
* sizeof(WCHAR
);
313 if (RegQueryValueExW(hKey
,
318 &dwLength
) != ERROR_SUCCESS
)
320 FatalError("Error: %lu\n", GetLastError());
325 if (!ExpandEnvironmentStringsW(szBuffer
,
329 FatalError("Error: %lu\n", GetLastError());
333 /* Create profiles directory */
334 if (!CreateDirectoryW(szTempDir
, NULL
))
336 if (GetLastError() != ERROR_ALREADY_EXISTS
)
338 FatalError("Error: %lu\n", GetLastError());
348 InstallSysSetupInfDevices(VOID
)
350 INFCONTEXT InfContext
;
351 WCHAR szLineBuffer
[256];
354 if (!SetupFindFirstLineW(hSysSetupInf
,
355 L
"DeviceInfsToInstall",
364 if (!SetupGetStringFieldW(&InfContext
,
367 sizeof(szLineBuffer
)/sizeof(szLineBuffer
[0]),
373 if (!SetupDiInstallClassW(NULL
, szLineBuffer
, DI_QUIETINSTALL
, NULL
))
378 while (SetupFindNextLine(&InfContext
, &InfContext
));
384 InstallSysSetupInfComponents(VOID
)
386 INFCONTEXT InfContext
;
387 WCHAR szNameBuffer
[256];
388 WCHAR szSectionBuffer
[256];
389 HINF hComponentInf
= INVALID_HANDLE_VALUE
;
391 if (!SetupFindFirstLineW(hSysSetupInf
,
396 DPRINT("No Inf.Always section found\n");
402 if (!SetupGetStringFieldW(&InfContext
,
403 1, // Get the component name
405 sizeof(szNameBuffer
)/sizeof(szNameBuffer
[0]),
408 FatalError("Error while trying to get component name \n");
412 if (!SetupGetStringFieldW(&InfContext
,
413 2, // Get the component install section
415 sizeof(szSectionBuffer
)/sizeof(szSectionBuffer
[0]),
418 FatalError("Error while trying to get component install section \n");
422 DPRINT("Trying to execute install section '%S' from '%S' \n", szSectionBuffer
, szNameBuffer
);
424 hComponentInf
= SetupOpenInfFileW(szNameBuffer
,
429 if (hComponentInf
== INVALID_HANDLE_VALUE
)
431 FatalError("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", szNameBuffer
, GetLastError());
435 if (!SetupInstallFromInfSectionW(NULL
,
442 SetupDefaultQueueCallbackW
,
447 FatalError("Error while trying to install : %S (Error: %lu)\n", szNameBuffer
, GetLastError());
448 SetupCloseInfFile(hComponentInf
);
452 SetupCloseInfFile(hComponentInf
);
454 while (SetupFindNextLine(&InfContext
, &InfContext
));
461 EnableUserModePnpManager(VOID
)
463 SC_HANDLE hSCManager
= NULL
;
464 SC_HANDLE hService
= NULL
;
467 hSCManager
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
468 if (hSCManager
== NULL
)
470 DPRINT1("Unable to open the service control manager.\n");
471 DPRINT1("Last Error %d\n", GetLastError());
475 hService
= OpenServiceW(hSCManager
,
477 SERVICE_CHANGE_CONFIG
| SERVICE_START
);
478 if (hService
== NULL
)
480 DPRINT1("Unable to open PlugPlay service\n");
484 bRet
= ChangeServiceConfigW(hService
,
489 NULL
, NULL
, NULL
, NULL
);
492 DPRINT1("Unable to change the service configuration\n");
496 bRet
= StartServiceW(hService
, 0, NULL
);
497 if (!bRet
&& (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
))
499 DPRINT1("Unable to start service\n");
506 if (hSCManager
!= NULL
)
507 CloseServiceHandle(hSCManager
);
508 if (hService
!= NULL
)
509 CloseServiceHandle(hService
);
513 static INT_PTR CALLBACK
514 StatusMessageWindowProc(
520 UNREFERENCED_PARAMETER(wParam
);
528 if (!LoadStringW(hDllInstance
, IDS_STATUS_INSTALL_DEV
, szMsg
, sizeof(szMsg
)/sizeof(szMsg
[0])))
530 SetDlgItemTextW(hwndDlg
, IDC_STATUSLABEL
, szMsg
);
538 ShowStatusMessageThread(
539 IN LPVOID lpParameter
)
541 HWND
*phWnd
= (HWND
*)lpParameter
;
545 hWnd
= CreateDialogParam(
547 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
549 StatusMessageWindowProc
,
555 ShowWindow(hWnd
, SW_SHOW
);
557 /* Message loop for the Status window */
558 while (GetMessage(&Msg
, NULL
, 0, 0))
560 TranslateMessage(&Msg
);
561 DispatchMessage(&Msg
);
579 return ERROR_INVALID_PARAMETER
;
582 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
583 if (rc
!= ERROR_SUCCESS
)
585 if (dwType
!= REG_SZ
)
586 return ERROR_FILE_NOT_FOUND
;
587 pwszValue
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
589 return ERROR_NOT_ENOUGH_MEMORY
;
590 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)pwszValue
, &cbData
);
591 if (rc
!= ERROR_SUCCESS
)
593 HeapFree(GetProcessHeap(), 0, pwszValue
);
596 /* NULL-terminate the string */
597 pwszValue
[cbData
/ sizeof(WCHAR
)] = '\0';
600 return ERROR_SUCCESS
;
606 HKEY hControlKey
= NULL
;
607 LPWSTR pwszSystemStartOptions
= NULL
;
608 LPWSTR pwszCurrentOption
, pwszNextOption
; /* Pointers into SystemStartOptions */
609 BOOL bConsoleBoot
= FALSE
;
614 L
"SYSTEM\\CurrentControlSet\\Control",
618 if (rc
!= ERROR_SUCCESS
)
621 rc
= ReadRegSzKey(hControlKey
, L
"SystemStartOptions", &pwszSystemStartOptions
);
622 if (rc
!= ERROR_SUCCESS
)
625 /* Check for CMDCONS in SystemStartOptions */
626 pwszCurrentOption
= pwszSystemStartOptions
;
627 while (pwszCurrentOption
)
629 pwszNextOption
= wcschr(pwszCurrentOption
, L
' ');
631 *pwszNextOption
= L
'\0';
632 if (wcsicmp(pwszCurrentOption
, L
"CONSOLE") == 0)
634 DPRINT("Found %S. Switching to console boot\n", pwszCurrentOption
);
638 pwszCurrentOption
= pwszNextOption
? pwszNextOption
+ 1 : NULL
;
642 if (hControlKey
!= NULL
)
643 RegCloseKey(hControlKey
);
644 if (pwszSystemStartOptions
)
645 HeapFree(GetProcessHeap(), 0, pwszSystemStartOptions
);
654 hSysSetupInf
= SetupOpenInfFileW(
659 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
661 FatalError("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
665 if (!InstallSysSetupInfDevices())
667 FatalError("InstallSysSetupInfDevices() failed!\n");
671 if(!InstallSysSetupInfComponents())
673 FatalError("InstallSysSetupInfComponents() failed!\n");
677 if (!IsConsoleBoot())
681 hThread
= CreateThread(
684 ShowStatusMessageThread
,
690 CloseHandle(hThread
);
693 if (!EnableUserModePnpManager())
695 FatalError("EnableUserModePnpManager() failed!\n");
699 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
701 FatalError("CMP_WaitNoPendingInstallEvents() failed!\n");
711 SetupCloseInfFile(hSysSetupInf
);
716 InstallLiveCD(IN HINSTANCE hInstance
)
718 STARTUPINFOW StartupInfo
;
719 PROCESS_INFORMATION ProcessInformation
;
722 if (!CommonInstall())
725 /* Register components */
728 if (!SetupInstallFromInfSectionW(NULL
,
729 hSysSetupInf
, L
"RegistrationPhase2",
731 0, NULL
, 0, NULL
, NULL
, NULL
, NULL
))
733 DPRINT1("SetupInstallFromInfSectionW failed!\n");
736 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
738 DPRINT1("Catching exception\n");
742 SetupCloseInfFile(hSysSetupInf
);
745 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
746 StartupInfo
.lpReserved
= NULL
;
747 StartupInfo
.lpDesktop
= NULL
;
748 StartupInfo
.lpTitle
= NULL
;
749 StartupInfo
.dwFlags
= 0;
750 StartupInfo
.cbReserved2
= 0;
751 StartupInfo
.lpReserved2
= 0;
752 bRes
= CreateProcessW(
762 &ProcessInformation
);
766 CloseHandle(ProcessInformation
.hThread
);
767 CloseHandle(ProcessInformation
.hProcess
);
774 L
"Failed to load LiveCD! You can shutdown your computer, or press ENTER to reboot.",
782 CreateShortcuts(VOID
)
788 /* Create desktop shortcuts */
789 CreateShortcut(CSIDL_DESKTOP
, NULL
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
, 0);
791 /* Create program startmenu shortcuts */
792 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_EXPLORER
, _T("%SystemRoot%\\explorer.exe"), IDS_CMT_EXPLORER
, TRUE
, 1);
793 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_DOWNLOADER
, _T("%SystemRoot%\\system32\\rapps.exe"), IDS_CMT_DOWNLOADER
, TRUE
, 0);
795 /* Create administrative tools startmenu shortcuts */
796 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_SERVICE
, _T("%SystemRoot%\\system32\\servman.exe"), IDS_CMT_SERVMAN
, TRUE
, 0);
797 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_DEVICE
, _T("%SystemRoot%\\system32\\devmgmt.exe"), IDS_CMT_DEVMGMT
, TRUE
, 0);
798 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_EVENTVIEW
, _T("%SystemRoot%\\system32\\eventvwr.exe"), IDS_CMT_EVENTVIEW
, TRUE
, 0);
799 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_MSCONFIG
, _T("%SystemRoot%\\system32\\msconfig.exe"), IDS_CMT_MSCONFIG
, TRUE
, 0);
801 /* Create and fill Accessories subfolder */
802 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_ACCESSORIES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
804 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CALC
, _T("%SystemRoot%\\system32\\calc.exe"), IDS_CMT_CALC
, TRUE
, 0);
805 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
, 0);
806 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_NOTEPAD
, _T("%SystemRoot%\\system32\\notepad.exe"), IDS_CMT_NOTEPAD
, TRUE
, 0);
807 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_RDESKTOP
, _T("%SystemRoot%\\system32\\mstsc.exe"), IDS_CMT_RDESKTOP
, TRUE
, 0);
808 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNAP
, _T("%SystemRoot%\\system32\\screenshot.exe"), IDS_CMT_SCREENSHOT
, TRUE
, 0);
809 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WORDPAD
, _T("%SystemRoot%\\system32\\wordpad.exe"), IDS_CMT_WORDPAD
, TRUE
, 0);
810 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_PAINT
, _T("%SystemRoot%\\system32\\mspaint.exe"), IDS_CMT_PAINT
, TRUE
, 0);
813 /* Create System Tools subfolder and fill if the exe is available */
814 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_TOOLS
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
816 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CHARMAP
, _T("%SystemRoot%\\system32\\charmap.exe"), IDS_CMT_CHARMAP
, TRUE
, 0);
817 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_KBSWITCH
, _T("%SystemRoot%\\system32\\kbswitch.exe"), IDS_CMT_KBSWITCH
, TRUE
, 0);
818 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_REGEDIT
, _T("%SystemRoot%\\regedit.exe"), IDS_CMT_REGEDIT
, TRUE
, 0);
819 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_DXDIAG
, _T("%SystemRoot%\\system32\\dxdiag.exe"), IDS_CMT_DXDIAG
, TRUE
, 0);
822 /* Create Accessibility subfolder and fill if the exe is available */
823 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ACCESSIBILITY
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
825 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MAGNIFY
, _T("%SystemRoot%\\system32\\magnify.exe"), IDS_CMT_MAGNIFY
, TRUE
, 0);
828 /* Create Entertainment subfolder and fill if the exe is available */
829 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ENTERTAINMENT
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
831 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MPLAY32
, _T("%SystemRoot%\\system32\\mplay32.exe"), IDS_CMT_MPLAY32
, TRUE
, 0);
832 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDVOL32
, _T("%SystemRoot%\\system32\\sndvol32.exe"), IDS_CMT_SNDVOL32
, TRUE
, 0);
833 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDREC32
, _T("%SystemRoot%\\system32\\sndrec32.exe"), IDS_CMT_SNDREC32
, TRUE
, 0);
836 /* Create Games subfolder and fill if the exe is available */
837 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_GAMES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
839 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SOLITAIRE
, _T("%SystemRoot%\\system32\\sol.exe"), IDS_CMT_SOLITAIRE
, TRUE
, 0);
840 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WINEMINE
, _T("%SystemRoot%\\system32\\winmine.exe"), IDS_CMT_WINEMINE
, TRUE
, 0);
841 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SPIDER
, _T("%SystemRoot%\\system32\\spider.exe"), IDS_CMT_SPIDER
, TRUE
, 0);
850 SetSetupType(DWORD dwSetupType
)
855 dwError
= RegOpenKeyExW(
861 if (dwError
!= ERROR_SUCCESS
)
864 dwError
= RegSetValueExW(
869 (LPBYTE
)&dwSetupType
,
872 if (dwError
!= ERROR_SUCCESS
)
879 InstallReactOS(HINSTANCE hInstance
)
881 TCHAR szBuffer
[MAX_PATH
];
884 TOKEN_PRIVILEGES privs
;
887 InitializeSetupActionLog(FALSE
);
888 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS");
890 if (!InitializeProfiles())
892 FatalError("InitializeProfiles() failed");
896 /* Initialize the Security Account Manager (SAM) */
897 if (!SamInitializeSAM())
899 FatalError("SamInitializeSAM() failed!");
903 /* Create the semi-random Domain-SID */
904 if (!CreateRandomSid(&DomainSid
))
906 FatalError("Domain-SID creation failed!");
910 /* Set the Domain SID (aka Computer SID) */
911 if (!SamSetDomainSid(DomainSid
))
913 FatalError("SamSetDomainSid() failed!");
914 RtlFreeSid(DomainSid
);
918 /* Append the Admin-RID */
919 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
921 CreateTempDir(L
"TEMP");
922 CreateTempDir(L
"TMP");
924 if (GetWindowsDirectory(szBuffer
, sizeof(szBuffer
) / sizeof(TCHAR
)))
926 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
927 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
930 &hKey
) == ERROR_SUCCESS
)
937 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
944 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
949 PathAddBackslash(szBuffer
);
950 _tcscat(szBuffer
, _T("system"));
951 CreateDirectory(szBuffer
, NULL
);
954 if (!CommonInstall())
959 /* Create the Administrator account */
960 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
962 /* Check what the error was.
963 * If the Admin Account already exists, then it means Setup
964 * wasn't allowed to finish properly. Instead of rebooting
965 * and not completing it, let it restart instead
967 LastError
= GetLastError();
968 if (LastError
!= ERROR_USER_EXISTS
)
970 FatalError("SamCreateUser() failed!");
971 RtlFreeSid(AdminSid
);
972 RtlFreeSid(DomainSid
);
977 RtlFreeSid(AdminSid
);
978 RtlFreeSid(DomainSid
);
980 if (!CreateShortcuts())
982 FatalError("CreateShortcuts() failed");
986 /* ROS HACK, as long as NtUnloadKey is not implemented */
988 NTSTATUS Status
= NtUnloadKey(NULL
);
989 if (Status
== STATUS_NOT_IMPLEMENTED
)
991 /* Create the Administrator profile */
992 PROFILEINFOW ProfileInfo
;
996 ret
= LogonUserW(L
"Administrator", L
"", L
"", LOGON32_LOGON_NETWORK
, LOGON32_PROVIDER_DEFAULT
, &hToken
);
999 FatalError("LogonUserW() failed!");
1002 ZeroMemory(&ProfileInfo
, sizeof(PROFILEINFOW
));
1003 ProfileInfo
.dwSize
= sizeof(PROFILEINFOW
);
1004 ProfileInfo
.lpUserName
= L
"Administrator";
1005 ProfileInfo
.dwFlags
= PI_NOUI
;
1006 LoadUserProfileW(hToken
, &ProfileInfo
);
1007 CloseHandle(hToken
);
1011 DPRINT1("ROS HACK not needed anymore. Please remove it\n");
1014 /* END OF ROS HACK */
1016 SetupCloseInfFile(hSysSetupInf
);
1019 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS done");
1020 TerminateSetupActionLog();
1022 /* Get shutdown privilege */
1023 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1025 FatalError("OpenProcessToken() failed!");
1028 if (!LookupPrivilegeValue(
1031 &privs
.Privileges
[0].Luid
))
1033 FatalError("LookupPrivilegeValue() failed!");
1036 privs
.PrivilegeCount
= 1;
1037 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1038 if (AdjustTokenPrivileges(
1043 (PTOKEN_PRIVILEGES
)NULL
,
1046 FatalError("AdjustTokenPrivileges() failed!");
1050 ExitWindowsEx(EWX_REBOOT
, 0);
1059 SetupChangeFontSize(
1061 IN LPCWSTR lpszFontSize
)
1063 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1071 SetupChangeLocaleEx(HWND hWnd
,
1073 LPCWSTR lpSrcRootPath
,
1078 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1086 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1088 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);