2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * PURPOSE: System setup
5 * FILE: dll/win32/syssetup/install.c
9 /* INCLUDES *****************************************************************/
24 #include <ndk/cmfuncs.h>
30 CMP_WaitNoPendingInstallEvents(DWORD dwTimeout
);
33 SetupStartService(LPCWSTR lpServiceName
, BOOL bWait
);
35 /* GLOBALS ******************************************************************/
37 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
40 /* FUNCTIONS ****************************************************************/
43 FatalError(char *pszFmt
,...)
49 vsprintf(szBuffer
, pszFmt
, ap
);
52 LogItem(NULL
, L
"Failed");
54 strcat(szBuffer
, "\nRebooting now!");
74 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
78 hr
= IShellLinkW_SetPath(psl
, pszCmd
);
81 hr
= IShellLinkW_SetArguments(psl
, pszArg
);
84 hr
= IShellLinkW_SetWorkingDirectory(psl
, pszDir
);
87 hr
= IShellLinkW_SetIconLocation(psl
, pszIconPath
, iIconNr
);
90 hr
= IShellLinkW_SetDescription(psl
, pszComment
);
92 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
96 hr
= IPersistFile_Save(ppf
, pszLinkPath
, TRUE
);
97 IPersistFile_Release(ppf
);
100 IShellLinkW_Release(psl
);
112 LPCWSTR pszDescription
,
114 LPCWSTR pszWorkingDir
)
119 WCHAR szPath
[MAX_PATH
];
120 WCHAR szWorkingDirBuf
[MAX_PATH
];
122 /* If no working directory is provided, try to compute a default one */
123 if (pszWorkingDir
== NULL
|| pszWorkingDir
[0] == L
'\0')
125 if (ExpandEnvironmentStringsW(pszCommand
, szPath
, ARRAYSIZE(szPath
)) == 0)
126 wcscpy(szPath
, pszCommand
);
128 dwLen
= GetFullPathNameW(szPath
,
129 ARRAYSIZE(szWorkingDirBuf
),
132 if (dwLen
!= 0 && dwLen
<= ARRAYSIZE(szWorkingDirBuf
))
134 /* Since those should only be called with (.exe) files,
135 lpFilePart has not to be NULL */
136 ASSERT(lpFilePart
!= NULL
);
138 /* We're only interested in the path. Cut the file name off.
139 Also remove the trailing backslash unless the working directory
140 is only going to be a drive, i.e. C:\ */
141 *(lpFilePart
--) = L
'\0';
142 if (!(lpFilePart
- szWorkingDirBuf
== 2 &&
143 szWorkingDirBuf
[1] == L
':' && szWorkingDirBuf
[2] == L
'\\'))
147 pszWorkingDir
= szWorkingDirBuf
;
151 /* If we failed to compute a working directory, just do not use one */
152 if (pszWorkingDir
&& pszWorkingDir
[0] == L
'\0')
153 pszWorkingDir
= NULL
;
155 /* Build the shortcut file name */
156 wcscpy(szPath
, pszFolder
);
157 Ptr
= PathAddBackslash(szPath
);
158 wcscpy(Ptr
, pszName
);
160 /* Create the shortcut */
161 return SUCCEEDED(CreateShellLink(szPath
,
165 /* Special value to indicate no icon */
166 (iIconNr
!= -1 ? pszCommand
: NULL
),
172 static BOOL
CreateShortcutsFromSection(HINF hinf
, LPWSTR pszSection
, LPCWSTR pszFolder
)
177 WCHAR szCommand
[MAX_PATH
];
178 WCHAR szName
[MAX_PATH
];
179 WCHAR szDescription
[MAX_PATH
];
180 WCHAR szDirectory
[MAX_PATH
];
182 if (!SetupFindFirstLine(hinf
, pszSection
, NULL
, &Context
))
187 dwFieldCount
= SetupGetFieldCount(&Context
);
188 if (dwFieldCount
< 3)
191 if (!SetupGetStringFieldW(&Context
, 1, szCommand
, ARRAYSIZE(szCommand
), NULL
))
194 if (!SetupGetStringFieldW(&Context
, 2, szName
, ARRAYSIZE(szName
), NULL
))
197 if (!SetupGetStringFieldW(&Context
, 3, szDescription
, ARRAYSIZE(szDescription
), NULL
))
200 if (dwFieldCount
< 4 || !SetupGetIntField(&Context
, 4, &iIconNr
))
201 iIconNr
= -1; /* Special value to indicate no icon */
203 if (dwFieldCount
< 5 || !SetupGetStringFieldW(&Context
, 5, szDirectory
, ARRAYSIZE(szDirectory
), NULL
))
204 szDirectory
[0] = L
'\0';
206 wcscat(szName
, L
".lnk");
208 CreateShortcut(pszFolder
, szName
, szCommand
, szDescription
, iIconNr
, szDirectory
);
210 } while (SetupFindNextLine(&Context
, &Context
));
215 static BOOL
CreateShortcuts(HINF hinf
, LPCWSTR szSection
)
218 WCHAR szPath
[MAX_PATH
];
219 WCHAR szFolder
[MAX_PATH
];
220 WCHAR szFolderSection
[MAX_PATH
];
225 if (!SetupFindFirstLine(hinf
, szSection
, NULL
, &Context
))
230 if (SetupGetFieldCount(&Context
) < 2)
233 if (!SetupGetStringFieldW(&Context
, 0, szFolderSection
, ARRAYSIZE(szFolderSection
), NULL
))
236 if (!SetupGetIntField(&Context
, 1, &csidl
))
239 if (!SetupGetStringFieldW(&Context
, 2, szFolder
, ARRAYSIZE(szFolder
), NULL
))
242 if (FAILED(SHGetFolderPathAndSubDirW(NULL
, csidl
|CSIDL_FLAG_CREATE
, (HANDLE
)-1, SHGFP_TYPE_DEFAULT
, szFolder
, szPath
)))
245 CreateShortcutsFromSection(hinf
, szFolderSection
, szPath
);
247 } while (SetupFindNextLine(&Context
, &Context
));
258 WCHAR szTempDir
[MAX_PATH
];
259 WCHAR szBuffer
[MAX_PATH
];
263 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
264 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
267 &hKey
) != ERROR_SUCCESS
)
269 FatalError("Error: %lu\n", GetLastError());
274 dwLength
= sizeof(szBuffer
);
275 if (RegQueryValueExW(hKey
,
280 &dwLength
) != ERROR_SUCCESS
)
282 FatalError("Error: %lu\n", GetLastError());
287 if (!ExpandEnvironmentStringsW(szBuffer
, szTempDir
, ARRAYSIZE(szTempDir
)))
289 FatalError("Error: %lu\n", GetLastError());
293 /* Create profiles directory */
294 if (!CreateDirectoryW(szTempDir
, NULL
))
296 if (GetLastError() != ERROR_ALREADY_EXISTS
)
298 FatalError("Error: %lu\n", GetLastError());
308 InstallSysSetupInfDevices(VOID
)
310 INFCONTEXT InfContext
;
311 WCHAR szLineBuffer
[256];
314 if (!SetupFindFirstLineW(hSysSetupInf
,
315 L
"DeviceInfsToInstall",
324 if (!SetupGetStringFieldW(&InfContext
,
327 ARRAYSIZE(szLineBuffer
),
333 if (!SetupDiInstallClassW(NULL
, szLineBuffer
, DI_QUIETINSTALL
, NULL
))
338 while (SetupFindNextLine(&InfContext
, &InfContext
));
344 InstallSysSetupInfComponents(VOID
)
346 INFCONTEXT InfContext
;
347 WCHAR szNameBuffer
[256];
348 WCHAR szSectionBuffer
[256];
349 HINF hComponentInf
= INVALID_HANDLE_VALUE
;
351 if (!SetupFindFirstLineW(hSysSetupInf
,
356 DPRINT("No Inf.Always section found\n");
362 if (!SetupGetStringFieldW(&InfContext
,
363 1, // Get the component name
365 ARRAYSIZE(szNameBuffer
),
368 FatalError("Error while trying to get component name \n");
372 if (!SetupGetStringFieldW(&InfContext
,
373 2, // Get the component install section
375 ARRAYSIZE(szSectionBuffer
),
378 FatalError("Error while trying to get component install section \n");
382 DPRINT("Trying to execute install section '%S' from '%S' \n", szSectionBuffer
, szNameBuffer
);
384 hComponentInf
= SetupOpenInfFileW(szNameBuffer
,
389 if (hComponentInf
== INVALID_HANDLE_VALUE
)
391 FatalError("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", szNameBuffer
, GetLastError());
395 if (!SetupInstallFromInfSectionW(NULL
,
402 SetupDefaultQueueCallbackW
,
407 FatalError("Error while trying to install : %S (Error: %lu)\n", szNameBuffer
, GetLastError());
408 SetupCloseInfFile(hComponentInf
);
412 SetupCloseInfFile(hComponentInf
);
414 while (SetupFindNextLine(&InfContext
, &InfContext
));
423 RegisterTypeLibraries(HINF hinf
, LPCWSTR szSection
)
425 INFCONTEXT InfContext
;
427 WCHAR szName
[MAX_PATH
];
428 WCHAR szPath
[MAX_PATH
];
434 /* Begin iterating the entries in the inf section */
435 res
= SetupFindFirstLine(hinf
, szSection
, NULL
, &InfContext
);
436 if (!res
) return FALSE
;
440 /* Get the name of the current type library */
441 if (!SetupGetStringFieldW(&InfContext
, 1, szName
, ARRAYSIZE(szName
), NULL
))
443 FatalError("SetupGetStringFieldW failed\n");
447 if (!SetupGetIntField(&InfContext
, 2, &csidl
))
448 csidl
= CSIDL_SYSTEM
;
450 hret
= SHGetFolderPathW(NULL
, csidl
, NULL
, 0, szPath
);
453 FatalError("SHGetFolderPathW failed hret=0x%lx\n", hret
);
457 p
= PathAddBackslash(szPath
);
460 hmod
= LoadLibraryW(szName
);
463 FatalError("LoadLibraryW failed\n");
467 __wine_register_resources(hmod
);
469 } while (SetupFindNextLine(&InfContext
, &InfContext
));
475 EnableUserModePnpManager(VOID
)
477 SC_HANDLE hSCManager
= NULL
;
478 SC_HANDLE hService
= NULL
;
481 hSCManager
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
482 if (hSCManager
== NULL
)
484 DPRINT1("Unable to open the service control manager.\n");
485 DPRINT1("Last Error %d\n", GetLastError());
489 hService
= OpenServiceW(hSCManager
,
491 SERVICE_CHANGE_CONFIG
| SERVICE_START
);
492 if (hService
== NULL
)
494 DPRINT1("Unable to open PlugPlay service\n");
498 bRet
= ChangeServiceConfigW(hService
,
503 NULL
, NULL
, NULL
, NULL
);
506 DPRINT1("Unable to change the service configuration\n");
510 bRet
= StartServiceW(hService
, 0, NULL
);
511 if (!bRet
&& (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
))
513 DPRINT1("Unable to start service\n");
520 if (hService
!= NULL
)
521 CloseServiceHandle(hService
);
522 if (hSCManager
!= NULL
)
523 CloseServiceHandle(hSCManager
);
527 static INT_PTR CALLBACK
528 StatusMessageWindowProc(
534 UNREFERENCED_PARAMETER(wParam
);
542 if (!LoadStringW(hDllInstance
, IDS_STATUS_INSTALL_DEV
, szMsg
, ARRAYSIZE(szMsg
)))
544 SetDlgItemTextW(hwndDlg
, IDC_STATUSLABEL
, szMsg
);
552 ShowStatusMessageThread(
553 IN LPVOID lpParameter
)
557 UNREFERENCED_PARAMETER(lpParameter
);
559 hWnd
= CreateDialogParam(hDllInstance
,
560 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
562 StatusMessageWindowProc
,
567 ShowWindow(hWnd
, SW_SHOW
);
569 hItem
= GetDlgItem(hWnd
, IDC_STATUSPROGRESS
);
572 PostMessage(hItem
, PBM_SETMARQUEE
, TRUE
, 40);
575 /* Message loop for the Status window */
576 while (GetMessage(&Msg
, NULL
, 0, 0))
578 TranslateMessage(&Msg
);
579 DispatchMessage(&Msg
);
599 return ERROR_INVALID_PARAMETER
;
602 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
603 if (rc
!= ERROR_SUCCESS
)
605 if (dwType
!= REG_SZ
)
606 return ERROR_FILE_NOT_FOUND
;
607 pwszValue
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
609 return ERROR_NOT_ENOUGH_MEMORY
;
610 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)pwszValue
, &cbData
);
611 if (rc
!= ERROR_SUCCESS
)
613 HeapFree(GetProcessHeap(), 0, pwszValue
);
616 /* NULL-terminate the string */
617 pwszValue
[cbData
/ sizeof(WCHAR
)] = '\0';
620 return ERROR_SUCCESS
;
626 HKEY hControlKey
= NULL
;
627 LPWSTR pwszSystemStartOptions
= NULL
;
628 LPWSTR pwszCurrentOption
, pwszNextOption
; /* Pointers into SystemStartOptions */
629 BOOL bConsoleBoot
= FALSE
;
632 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
633 L
"SYSTEM\\CurrentControlSet\\Control",
637 if (rc
!= ERROR_SUCCESS
)
640 rc
= ReadRegSzKey(hControlKey
, L
"SystemStartOptions", &pwszSystemStartOptions
);
641 if (rc
!= ERROR_SUCCESS
)
644 /* Check for CONSOLE switch in SystemStartOptions */
645 pwszCurrentOption
= pwszSystemStartOptions
;
646 while (pwszCurrentOption
)
648 pwszNextOption
= wcschr(pwszCurrentOption
, L
' ');
650 *pwszNextOption
= L
'\0';
651 if (wcsicmp(pwszCurrentOption
, L
"CONSOLE") == 0)
653 DPRINT("Found %S. Switching to console boot\n", pwszCurrentOption
);
657 pwszCurrentOption
= pwszNextOption
? pwszNextOption
+ 1 : NULL
;
661 if (hControlKey
!= NULL
)
662 RegCloseKey(hControlKey
);
663 if (pwszSystemStartOptions
)
664 HeapFree(GetProcessHeap(), 0, pwszSystemStartOptions
);
671 HANDLE hThread
= NULL
;
672 BOOL bResult
= FALSE
;
674 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
678 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
680 FatalError("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
684 if (!InstallSysSetupInfDevices())
686 FatalError("InstallSysSetupInfDevices() failed!\n");
690 if(!InstallSysSetupInfComponents())
692 FatalError("InstallSysSetupInfComponents() failed!\n");
696 if (!IsConsoleBoot())
698 hThread
= CreateThread(NULL
,
700 ShowStatusMessageThread
,
706 if (!EnableUserModePnpManager())
708 FatalError("EnableUserModePnpManager() failed!\n");
712 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
714 FatalError("CMP_WaitNoPendingInstallEvents() failed!\n");
722 if (bResult
== FALSE
)
724 SetupCloseInfFile(hSysSetupInf
);
729 PostThreadMessage(GetThreadId(hThread
), WM_QUIT
, 0, 0);
730 WaitForSingleObject(hThread
, INFINITE
);
731 CloseHandle(hThread
);
741 STARTUPINFOW StartupInfo
;
742 PROCESS_INFORMATION ProcessInformation
;
745 if (!CommonInstall())
748 /* Install the TCP/IP protocol driver */
749 bRes
= InstallNetworkComponent(L
"MS_TCPIP");
750 if (!bRes
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
752 DPRINT("InstallNetworkComponent() failed with error 0x%lx\n", GetLastError());
756 /* Start the TCP/IP protocol driver */
757 SetupStartService(L
"Tcpip", FALSE
);
758 SetupStartService(L
"Dhcp", FALSE
);
761 /* Register components */
764 if (!SetupInstallFromInfSectionW(NULL
,
765 hSysSetupInf
, L
"RegistrationPhase2",
767 0, NULL
, 0, NULL
, NULL
, NULL
, NULL
))
769 DPRINT1("SetupInstallFromInfSectionW failed!\n");
772 RegisterTypeLibraries(hSysSetupInf
, L
"TypeLibraries");
774 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
776 DPRINT1("Catching exception\n");
780 SetupCloseInfFile(hSysSetupInf
);
783 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
784 StartupInfo
.cb
= sizeof(StartupInfo
);
785 bRes
= CreateProcessW(L
"userinit.exe",
794 &ProcessInformation
);
798 CloseHandle(ProcessInformation
.hThread
);
799 CloseHandle(ProcessInformation
.hProcess
);
806 L
"Failed to load LiveCD! You can shutdown your computer, or press ENTER to reboot.",
814 SetSetupType(DWORD dwSetupType
)
819 dwError
= RegOpenKeyExW(
825 if (dwError
!= ERROR_SUCCESS
)
828 dwError
= RegSetValueExW(
833 (LPBYTE
)&dwSetupType
,
836 if (dwError
!= ERROR_SUCCESS
)
842 static DWORD CALLBACK
843 HotkeyThread(LPVOID Parameter
)
848 DPRINT("HotkeyThread start\n");
850 hotkey
= GlobalAddAtomW(L
"Setup Shift+F10 Hotkey");
852 if (!RegisterHotKey(NULL
, hotkey
, MOD_SHIFT
, VK_F10
))
853 DPRINT1("RegisterHotKey failed with %lu\n", GetLastError());
855 while (GetMessage(&msg
, NULL
, 0, 0))
857 if (msg
.hwnd
== NULL
&& msg
.message
== WM_HOTKEY
&& msg
.wParam
== hotkey
)
859 STARTUPINFOW si
= { sizeof(si
) };
860 PROCESS_INFORMATION pi
;
862 if (CreateProcessW(L
"cmd.exe",
873 CloseHandle(pi
.hProcess
);
874 CloseHandle(pi
.hThread
);
878 DPRINT1("Failed to launch command prompt: %lu\n", GetLastError());
883 UnregisterHotKey(NULL
, hotkey
);
884 GlobalDeleteAtom(hotkey
);
886 DPRINT("HotkeyThread terminate\n");
893 InitializeProgramFilesDir(VOID
)
898 WCHAR szProgramFilesDirPath
[MAX_PATH
];
899 WCHAR szCommonFilesDirPath
[MAX_PATH
];
900 WCHAR szBuffer
[MAX_PATH
];
902 /* Load 'Program Files' location */
903 if (!LoadStringW(hDllInstance
,
906 ARRAYSIZE(szBuffer
)))
908 DPRINT1("Error: %lu\n", GetLastError());
912 if (!LoadStringW(hDllInstance
,
914 szCommonFilesDirPath
,
915 ARRAYSIZE(szCommonFilesDirPath
)))
917 DPRINT1("Warning: %lu\n", GetLastError());
921 if (!ExpandEnvironmentStringsW(szBuffer
,
922 szProgramFilesDirPath
,
923 ARRAYSIZE(szProgramFilesDirPath
)))
925 DPRINT1("Error: %lu\n", GetLastError());
929 wcscpy(szBuffer
, szProgramFilesDirPath
);
930 wcscat(szBuffer
, L
"\\");
931 wcscat(szBuffer
, szCommonFilesDirPath
);
933 if (!ExpandEnvironmentStringsW(szBuffer
,
934 szCommonFilesDirPath
,
935 ARRAYSIZE(szCommonFilesDirPath
)))
937 DPRINT1("Warning: %lu\n", GetLastError());
941 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
942 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
946 if (Error
!= ERROR_SUCCESS
)
948 DPRINT1("Error: %lu\n", Error
);
952 dwLength
= (wcslen(szProgramFilesDirPath
) + 1) * sizeof(WCHAR
);
953 Error
= RegSetValueExW(hKey
,
957 (LPBYTE
)szProgramFilesDirPath
,
959 if (Error
!= ERROR_SUCCESS
)
961 DPRINT1("Error: %lu\n", Error
);
966 dwLength
= (wcslen(szCommonFilesDirPath
) + 1) * sizeof(WCHAR
);
967 Error
= RegSetValueExW(hKey
,
971 (LPBYTE
)szCommonFilesDirPath
,
973 if (Error
!= ERROR_SUCCESS
)
975 DPRINT1("Warning: %lu\n", Error
);
980 /* Create directory */
982 if (!CreateDirectoryW(szProgramFilesDirPath
, NULL
))
984 if (GetLastError() != ERROR_ALREADY_EXISTS
)
986 DPRINT1("Error: %lu\n", GetLastError());
991 /* Create directory */
993 if (!CreateDirectoryW(szCommonFilesDirPath
, NULL
))
995 if (GetLastError() != ERROR_ALREADY_EXISTS
)
997 DPRINT1("Warning: %lu\n", GetLastError());
1008 InitializeDefaultUserLocale(VOID
)
1018 struct {LCTYPE LCType
; PWSTR pValue
;} LocaleData
[] = {
1020 {LOCALE_SDECIMAL
, L
"sDecimal"},
1021 {LOCALE_STHOUSAND
, L
"sThousand"},
1022 {LOCALE_SNEGATIVESIGN
, L
"sNegativeSign"},
1023 {LOCALE_SPOSITIVESIGN
, L
"sPositiveSign"},
1024 {LOCALE_SGROUPING
, L
"sGrouping"},
1025 {LOCALE_SLIST
, L
"sList"},
1026 {LOCALE_SNATIVEDIGITS
, L
"sNativeDigits"},
1027 {LOCALE_INEGNUMBER
, L
"iNegNumber"},
1028 {LOCALE_IDIGITS
, L
"iDigits"},
1029 {LOCALE_ILZERO
, L
"iLZero"},
1030 {LOCALE_IMEASURE
, L
"iMeasure"},
1031 {LOCALE_IDIGITSUBSTITUTION
, L
"NumShape"},
1034 {LOCALE_SCURRENCY
, L
"sCurrency"},
1035 {LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep"},
1036 {LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep"},
1037 {LOCALE_SMONGROUPING
, L
"sMonGrouping"},
1038 {LOCALE_ICURRENCY
, L
"iCurrency"},
1039 {LOCALE_INEGCURR
, L
"iNegCurr"},
1040 {LOCALE_ICURRDIGITS
, L
"iCurrDigits"},
1043 {LOCALE_STIMEFORMAT
, L
"sTimeFormat"},
1044 {LOCALE_STIME
, L
"sTime"},
1045 {LOCALE_S1159
, L
"s1159"},
1046 {LOCALE_S2359
, L
"s2359"},
1047 {LOCALE_ITIME
, L
"iTime"},
1048 {LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix"},
1049 {LOCALE_ITLZERO
, L
"iTLZero"},
1052 {LOCALE_SLONGDATE
, L
"sLongDate"},
1053 {LOCALE_SSHORTDATE
, L
"sShortDate"},
1054 {LOCALE_SDATE
, L
"sDate"},
1055 {LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek"},
1056 {LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear"},
1057 {LOCALE_IDATE
, L
"iDate"},
1058 {LOCALE_ICALENDARTYPE
, L
"iCalendarType"},
1061 {LOCALE_SCOUNTRY
, L
"sCountry"},
1062 {LOCALE_SABBREVLANGNAME
, L
"sLanguage"},
1063 {LOCALE_ICOUNTRY
, L
"iCountry"},
1066 ret
= RegOpenKeyExW(HKEY_USERS
,
1067 L
".DEFAULT\\Control Panel\\International",
1069 KEY_READ
| KEY_WRITE
,
1071 if (ret
!= ERROR_SUCCESS
)
1076 dwSize
= 9 * sizeof(WCHAR
);
1077 ret
= RegQueryValueExW(hLocaleKey
,
1083 if (ret
!= ERROR_SUCCESS
)
1086 lcid
= (LCID
)wcstoul(szBuffer
, &ptr
, 16);
1091 while (LocaleData
[i
].pValue
!= NULL
)
1093 if (GetLocaleInfoW(lcid
,
1094 LocaleData
[i
].LCType
| LOCALE_NOUSEROVERRIDE
,
1096 ARRAYSIZE(szBuffer
)))
1098 RegSetValueExW(hLocaleKey
,
1099 LocaleData
[i
].pValue
,
1103 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1110 RegCloseKey(hLocaleKey
);
1116 SaveDefaultUserHive(VOID
)
1118 WCHAR szDefaultUserHive
[MAX_PATH
];
1119 HKEY hUserKey
= NULL
;
1123 DPRINT("SaveDefaultUserHive()\n");
1125 cchSize
= ARRAYSIZE(szDefaultUserHive
);
1126 GetDefaultUserProfileDirectoryW(szDefaultUserHive
, &cchSize
);
1128 wcscat(szDefaultUserHive
, L
"\\ntuser.dat");
1130 dwError
= RegOpenKeyExW(HKEY_USERS
,
1135 if (dwError
!= ERROR_SUCCESS
)
1137 DPRINT1("RegOpenKeyExW() failed (Error %lu)\n", dwError
);
1141 pSetupEnablePrivilege(L
"SeBackupPrivilege", TRUE
);
1143 /* Save the Default hive */
1144 dwError
= RegSaveKeyExW(hUserKey
,
1147 REG_STANDARD_FORMAT
);
1148 if (dwError
== ERROR_ALREADY_EXISTS
)
1150 WCHAR szBackupHive
[MAX_PATH
];
1152 /* Build the backup hive file name by replacing the extension */
1153 wcscpy(szBackupHive
, szDefaultUserHive
);
1154 wcscpy(&szBackupHive
[wcslen(szBackupHive
) - 4], L
".bak");
1156 /* Back up the existing default user hive by renaming it, replacing any possible existing old backup */
1157 if (!MoveFileExW(szDefaultUserHive
,
1159 MOVEFILE_REPLACE_EXISTING
))
1161 dwError
= GetLastError();
1162 DPRINT1("Failed to create a default-user hive backup '%S', MoveFileExW failed (Error %lu)\n",
1163 szBackupHive
, dwError
);
1167 /* The backup has been done, retry saving the Default hive */
1168 dwError
= RegSaveKeyExW(hUserKey
,
1171 REG_STANDARD_FORMAT
);
1174 if (dwError
!= ERROR_SUCCESS
)
1176 DPRINT1("RegSaveKeyExW() failed (Error %lu)\n", dwError
);
1179 pSetupEnablePrivilege(L
"SeBackupPrivilege", FALSE
);
1181 RegCloseKey(hUserKey
);
1189 InstallReactOS(VOID
)
1191 WCHAR szBuffer
[MAX_PATH
];
1193 TOKEN_PRIVILEGES privs
;
1196 HANDLE hHotkeyThread
;
1199 InitializeSetupActionLog(FALSE
);
1200 LogItem(NULL
, L
"Installing ReactOS");
1202 CreateTempDir(L
"TEMP");
1203 CreateTempDir(L
"TMP");
1205 if (!InitializeProgramFilesDir())
1207 FatalError("InitializeProgramFilesDir() failed");
1211 if (!InitializeProfiles())
1213 FatalError("InitializeProfiles() failed");
1217 InitializeDefaultUserLocale();
1219 if (GetWindowsDirectoryW(szBuffer
, ARRAYSIZE(szBuffer
)))
1221 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1222 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
1225 &hKey
) == ERROR_SUCCESS
)
1227 RegSetValueExW(hKey
,
1232 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1234 RegSetValueExW(hKey
,
1239 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1244 PathAddBackslash(szBuffer
);
1245 wcscat(szBuffer
, L
"system");
1246 CreateDirectory(szBuffer
, NULL
);
1249 if (SaveDefaultUserHive() != ERROR_SUCCESS
)
1251 FatalError("SaveDefaultUserHive() failed");
1255 if (!CopySystemProfile(0))
1257 FatalError("CopySystemProfile() failed");
1261 hHotkeyThread
= CreateThread(NULL
, 0, HotkeyThread
, NULL
, 0, NULL
);
1263 if (!CommonInstall())
1266 /* Install the TCP/IP protocol driver */
1267 ret
= InstallNetworkComponent(L
"MS_TCPIP");
1268 if (!ret
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
1270 DPRINT("InstallNetworkComponent() failed with error 0x%lx\n", GetLastError());
1274 /* Start the TCP/IP protocol driver */
1275 SetupStartService(L
"Tcpip", FALSE
);
1276 SetupStartService(L
"Dhcp", FALSE
);
1283 SetAutoAdminLogon();
1285 hShortcutsInf
= SetupOpenInfFileW(L
"shortcuts.inf",
1289 if (hShortcutsInf
== INVALID_HANDLE_VALUE
)
1291 FatalError("Failed to open shortcuts.inf");
1295 if (!CreateShortcuts(hShortcutsInf
, L
"ShortcutFolders"))
1297 FatalError("CreateShortcuts() failed");
1301 SetupCloseInfFile(hShortcutsInf
);
1303 hShortcutsInf
= SetupOpenInfFileW(L
"rosapps_shortcuts.inf",
1307 if (hShortcutsInf
!= INVALID_HANDLE_VALUE
)
1309 if (!CreateShortcuts(hShortcutsInf
, L
"ShortcutFolders"))
1311 FatalError("CreateShortcuts(rosapps) failed");
1314 SetupCloseInfFile(hShortcutsInf
);
1317 SetupCloseInfFile(hSysSetupInf
);
1322 PostThreadMessage(GetThreadId(hHotkeyThread
), WM_QUIT
, 0, 0);
1323 CloseHandle(hHotkeyThread
);
1326 LogItem(NULL
, L
"Installing ReactOS done");
1327 TerminateSetupActionLog();
1329 if (AdminInfo
.Name
!= NULL
)
1330 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Name
);
1332 if (AdminInfo
.Domain
!= NULL
)
1333 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Domain
);
1335 if (AdminInfo
.Password
!= NULL
)
1336 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Password
);
1338 /* Get shutdown privilege */
1339 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1341 FatalError("OpenProcessToken() failed!");
1344 if (!LookupPrivilegeValue(NULL
,
1346 &privs
.Privileges
[0].Luid
))
1348 FatalError("LookupPrivilegeValue() failed!");
1351 privs
.PrivilegeCount
= 1;
1352 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1353 if (AdjustTokenPrivileges(token
,
1357 (PTOKEN_PRIVILEGES
)NULL
,
1360 FatalError("AdjustTokenPrivileges() failed!");
1364 ExitWindowsEx(EWX_REBOOT
, 0);
1370 * Standard Windows-compatible export, which dispatches
1371 * to either 'InstallReactOS' or 'InstallLiveCD'.
1375 InstallWindowsNt(INT argc
, WCHAR
** argv
)
1380 for (i
= 0; i
< argc
; ++i
)
1387 // NOTE: On Windows, "mini" means "minimal UI", and can be used
1388 // in addition to "newsetup"; these options are not exclusive.
1389 if (_wcsicmp(p
, L
"newsetup") == 0)
1390 return (INT
)InstallReactOS();
1391 else if (_wcsicmp(p
, L
"mini") == 0)
1392 return (INT
)InstallLiveCD();
1394 /* Add support for other switches */
1406 SetupChangeFontSize(
1408 IN LPCWSTR lpszFontSize
)
1410 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1418 SetupChangeLocaleEx(HWND hWnd
,
1420 LPCWSTR lpSrcRootPath
,
1425 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1433 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1435 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);
1442 LPCWSTR lpServiceName
,
1445 SC_HANDLE hManager
= NULL
;
1446 SC_HANDLE hService
= NULL
;
1447 DWORD dwError
= ERROR_SUCCESS
;
1449 hManager
= OpenSCManagerW(NULL
,
1451 SC_MANAGER_ALL_ACCESS
);
1452 if (hManager
== NULL
)
1454 dwError
= GetLastError();
1458 hService
= OpenServiceW(hManager
,
1461 if (hService
== NULL
)
1463 dwError
= GetLastError();
1467 if (!StartService(hService
, 0, NULL
))
1469 dwError
= GetLastError();
1474 if (hService
!= NULL
)
1475 CloseServiceHandle(hService
);
1477 if (hManager
!= NULL
)
1478 CloseServiceHandle(hManager
);