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
)
555 HWND
*phWnd
= (HWND
*)lpParameter
;
559 hWnd
= CreateDialogParam(hDllInstance
,
560 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
562 StatusMessageWindowProc
,
568 ShowWindow(hWnd
, SW_SHOW
);
570 hItem
= GetDlgItem(hWnd
, IDC_STATUSPROGRESS
);
573 PostMessage(hItem
, PBM_SETMARQUEE
, TRUE
, 40);
576 /* Message loop for the Status window */
577 while (GetMessage(&Msg
, NULL
, 0, 0))
579 TranslateMessage(&Msg
);
580 DispatchMessage(&Msg
);
598 return ERROR_INVALID_PARAMETER
;
601 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
602 if (rc
!= ERROR_SUCCESS
)
604 if (dwType
!= REG_SZ
)
605 return ERROR_FILE_NOT_FOUND
;
606 pwszValue
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
608 return ERROR_NOT_ENOUGH_MEMORY
;
609 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)pwszValue
, &cbData
);
610 if (rc
!= ERROR_SUCCESS
)
612 HeapFree(GetProcessHeap(), 0, pwszValue
);
615 /* NULL-terminate the string */
616 pwszValue
[cbData
/ sizeof(WCHAR
)] = '\0';
619 return ERROR_SUCCESS
;
625 HKEY hControlKey
= NULL
;
626 LPWSTR pwszSystemStartOptions
= NULL
;
627 LPWSTR pwszCurrentOption
, pwszNextOption
; /* Pointers into SystemStartOptions */
628 BOOL bConsoleBoot
= FALSE
;
631 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
632 L
"SYSTEM\\CurrentControlSet\\Control",
636 if (rc
!= ERROR_SUCCESS
)
639 rc
= ReadRegSzKey(hControlKey
, L
"SystemStartOptions", &pwszSystemStartOptions
);
640 if (rc
!= ERROR_SUCCESS
)
643 /* Check for CONSOLE switch in SystemStartOptions */
644 pwszCurrentOption
= pwszSystemStartOptions
;
645 while (pwszCurrentOption
)
647 pwszNextOption
= wcschr(pwszCurrentOption
, L
' ');
649 *pwszNextOption
= L
'\0';
650 if (wcsicmp(pwszCurrentOption
, L
"CONSOLE") == 0)
652 DPRINT("Found %S. Switching to console boot\n", pwszCurrentOption
);
656 pwszCurrentOption
= pwszNextOption
? pwszNextOption
+ 1 : NULL
;
660 if (hControlKey
!= NULL
)
661 RegCloseKey(hControlKey
);
662 if (pwszSystemStartOptions
)
663 HeapFree(GetProcessHeap(), 0, pwszSystemStartOptions
);
672 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
676 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
678 FatalError("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
682 if (!InstallSysSetupInfDevices())
684 FatalError("InstallSysSetupInfDevices() failed!\n");
688 if(!InstallSysSetupInfComponents())
690 FatalError("InstallSysSetupInfComponents() failed!\n");
694 if (!IsConsoleBoot())
698 hThread
= CreateThread(NULL
,
700 ShowStatusMessageThread
,
705 CloseHandle(hThread
);
708 if (!EnableUserModePnpManager())
710 FatalError("EnableUserModePnpManager() failed!\n");
714 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
716 FatalError("CMP_WaitNoPendingInstallEvents() failed!\n");
726 SetupCloseInfFile(hSysSetupInf
);
730 /* Install a section of a .inf file
731 * Returns TRUE if success, FALSE if failure. Error code can
732 * be retrieved with GetLastError()
739 IN LPCWSTR InfSection OPTIONAL
,
740 IN LPCWSTR InfService OPTIONAL
)
742 WCHAR Buffer
[MAX_PATH
];
743 HINF hInf
= INVALID_HANDLE_VALUE
;
745 PVOID Context
= NULL
;
748 /* Get Windows directory */
749 BufferSize
= ARRAYSIZE(Buffer
) - 5 - wcslen(InfFile
);
750 if (GetWindowsDirectoryW(Buffer
, BufferSize
) > BufferSize
)
752 /* Function failed */
753 SetLastError(ERROR_GEN_FAILURE
);
756 /* We have enough space to add some information in the buffer */
757 if (Buffer
[wcslen(Buffer
) - 1] != '\\')
758 wcscat(Buffer
, L
"\\");
759 wcscat(Buffer
, L
"Inf\\");
760 wcscat(Buffer
, InfFile
);
762 /* Install specified section */
763 hInf
= SetupOpenInfFileW(Buffer
, NULL
, INF_STYLE_WIN4
, NULL
);
764 if (hInf
== INVALID_HANDLE_VALUE
)
767 Context
= SetupInitDefaultQueueCallback(hWnd
);
772 if (ret
&& InfSection
)
774 ret
= SetupInstallFromInfSectionW(
776 InfSection
, SPINST_ALL
,
777 NULL
, NULL
, SP_COPY_NEWER
,
778 SetupDefaultQueueCallbackW
, Context
,
781 if (ret
&& InfService
)
783 ret
= SetupInstallServicesFromInfSectionW(hInf
, InfService
, 0);
788 SetupTermDefaultQueueCallback(Context
);
789 if (hInf
!= INVALID_HANDLE_VALUE
)
790 SetupCloseInfFile(hInf
);
798 STARTUPINFOW StartupInfo
;
799 PROCESS_INFORMATION ProcessInformation
;
802 /* Hack: Install TCP/IP protocol driver */
803 bRes
= InstallInfSection(NULL
,
805 L
"MS_TCPIP.PrimaryInstall",
806 L
"MS_TCPIP.PrimaryInstall.Services");
807 if (!bRes
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
809 DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError());
813 /* Start the TCP/IP protocol driver */
814 SetupStartService(L
"Tcpip", FALSE
);
815 SetupStartService(L
"Dhcp", FALSE
);
818 if (!CommonInstall())
821 /* Register components */
824 if (!SetupInstallFromInfSectionW(NULL
,
825 hSysSetupInf
, L
"RegistrationPhase2",
827 0, NULL
, 0, NULL
, NULL
, NULL
, NULL
))
829 DPRINT1("SetupInstallFromInfSectionW failed!\n");
832 RegisterTypeLibraries(hSysSetupInf
, L
"TypeLibraries");
834 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
836 DPRINT1("Catching exception\n");
840 SetupCloseInfFile(hSysSetupInf
);
843 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
844 StartupInfo
.cb
= sizeof(StartupInfo
);
845 bRes
= CreateProcessW(L
"userinit.exe",
854 &ProcessInformation
);
858 CloseHandle(ProcessInformation
.hThread
);
859 CloseHandle(ProcessInformation
.hProcess
);
866 L
"Failed to load LiveCD! You can shutdown your computer, or press ENTER to reboot.",
874 SetSetupType(DWORD dwSetupType
)
879 dwError
= RegOpenKeyExW(
885 if (dwError
!= ERROR_SUCCESS
)
888 dwError
= RegSetValueExW(
893 (LPBYTE
)&dwSetupType
,
896 if (dwError
!= ERROR_SUCCESS
)
902 static DWORD CALLBACK
903 HotkeyThread(LPVOID Parameter
)
908 DPRINT("HotkeyThread start\n");
910 hotkey
= GlobalAddAtomW(L
"Setup Shift+F10 Hotkey");
912 if (!RegisterHotKey(NULL
, hotkey
, MOD_SHIFT
, VK_F10
))
913 DPRINT1("RegisterHotKey failed with %lu\n", GetLastError());
915 while (GetMessage(&msg
, NULL
, 0, 0))
917 if (msg
.hwnd
== NULL
&& msg
.message
== WM_HOTKEY
&& msg
.wParam
== hotkey
)
919 STARTUPINFOW si
= { sizeof(si
) };
920 PROCESS_INFORMATION pi
;
922 if (CreateProcessW(L
"cmd.exe",
933 CloseHandle(pi
.hProcess
);
934 CloseHandle(pi
.hThread
);
938 DPRINT1("Failed to launch command prompt: %lu\n", GetLastError());
943 UnregisterHotKey(NULL
, hotkey
);
944 GlobalDeleteAtom(hotkey
);
946 DPRINT("HotkeyThread terminate\n");
953 InitializeProgramFilesDir(VOID
)
958 WCHAR szProgramFilesDirPath
[MAX_PATH
];
959 WCHAR szCommonFilesDirPath
[MAX_PATH
];
960 WCHAR szBuffer
[MAX_PATH
];
962 /* Load 'Program Files' location */
963 if (!LoadStringW(hDllInstance
,
966 ARRAYSIZE(szBuffer
)))
968 DPRINT1("Error: %lu\n", GetLastError());
972 if (!LoadStringW(hDllInstance
,
974 szCommonFilesDirPath
,
975 ARRAYSIZE(szCommonFilesDirPath
)))
977 DPRINT1("Warning: %lu\n", GetLastError());
981 if (!ExpandEnvironmentStringsW(szBuffer
,
982 szProgramFilesDirPath
,
983 ARRAYSIZE(szProgramFilesDirPath
)))
985 DPRINT1("Error: %lu\n", GetLastError());
989 wcscpy(szBuffer
, szProgramFilesDirPath
);
990 wcscat(szBuffer
, L
"\\");
991 wcscat(szBuffer
, szCommonFilesDirPath
);
993 if (!ExpandEnvironmentStringsW(szBuffer
,
994 szCommonFilesDirPath
,
995 ARRAYSIZE(szCommonFilesDirPath
)))
997 DPRINT1("Warning: %lu\n", GetLastError());
1001 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1002 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
1006 if (Error
!= ERROR_SUCCESS
)
1008 DPRINT1("Error: %lu\n", Error
);
1012 dwLength
= (wcslen(szProgramFilesDirPath
) + 1) * sizeof(WCHAR
);
1013 Error
= RegSetValueExW(hKey
,
1017 (LPBYTE
)szProgramFilesDirPath
,
1019 if (Error
!= ERROR_SUCCESS
)
1021 DPRINT1("Error: %lu\n", Error
);
1026 dwLength
= (wcslen(szCommonFilesDirPath
) + 1) * sizeof(WCHAR
);
1027 Error
= RegSetValueExW(hKey
,
1031 (LPBYTE
)szCommonFilesDirPath
,
1033 if (Error
!= ERROR_SUCCESS
)
1035 DPRINT1("Warning: %lu\n", Error
);
1040 /* Create directory */
1042 if (!CreateDirectoryW(szProgramFilesDirPath
, NULL
))
1044 if (GetLastError() != ERROR_ALREADY_EXISTS
)
1046 DPRINT1("Error: %lu\n", GetLastError());
1051 /* Create directory */
1053 if (!CreateDirectoryW(szCommonFilesDirPath
, NULL
))
1055 if (GetLastError() != ERROR_ALREADY_EXISTS
)
1057 DPRINT1("Warning: %lu\n", GetLastError());
1068 InitializeDefaultUserLocale(VOID
)
1078 struct {LCTYPE LCType
; PWSTR pValue
;} LocaleData
[] = {
1080 {LOCALE_SDECIMAL
, L
"sDecimal"},
1081 {LOCALE_STHOUSAND
, L
"sThousand"},
1082 {LOCALE_SNEGATIVESIGN
, L
"sNegativeSign"},
1083 {LOCALE_SPOSITIVESIGN
, L
"sPositiveSign"},
1084 {LOCALE_SGROUPING
, L
"sGrouping"},
1085 {LOCALE_SLIST
, L
"sList"},
1086 {LOCALE_SNATIVEDIGITS
, L
"sNativeDigits"},
1087 {LOCALE_INEGNUMBER
, L
"iNegNumber"},
1088 {LOCALE_IDIGITS
, L
"iDigits"},
1089 {LOCALE_ILZERO
, L
"iLZero"},
1090 {LOCALE_IMEASURE
, L
"iMeasure"},
1091 {LOCALE_IDIGITSUBSTITUTION
, L
"NumShape"},
1094 {LOCALE_SCURRENCY
, L
"sCurrency"},
1095 {LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep"},
1096 {LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep"},
1097 {LOCALE_SMONGROUPING
, L
"sMonGrouping"},
1098 {LOCALE_ICURRENCY
, L
"iCurrency"},
1099 {LOCALE_INEGCURR
, L
"iNegCurr"},
1100 {LOCALE_ICURRDIGITS
, L
"iCurrDigits"},
1103 {LOCALE_STIMEFORMAT
, L
"sTimeFormat"},
1104 {LOCALE_STIME
, L
"sTime"},
1105 {LOCALE_S1159
, L
"s1159"},
1106 {LOCALE_S2359
, L
"s2359"},
1107 {LOCALE_ITIME
, L
"iTime"},
1108 {LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix"},
1109 {LOCALE_ITLZERO
, L
"iTLZero"},
1112 {LOCALE_SLONGDATE
, L
"sLongDate"},
1113 {LOCALE_SSHORTDATE
, L
"sShortDate"},
1114 {LOCALE_SDATE
, L
"sDate"},
1115 {LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek"},
1116 {LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear"},
1117 {LOCALE_IDATE
, L
"iDate"},
1118 {LOCALE_ICALENDARTYPE
, L
"iCalendarType"},
1121 {LOCALE_SCOUNTRY
, L
"sCountry"},
1122 {LOCALE_SABBREVLANGNAME
, L
"sLanguage"},
1123 {LOCALE_ICOUNTRY
, L
"iCountry"},
1126 ret
= RegOpenKeyExW(HKEY_USERS
,
1127 L
".DEFAULT\\Control Panel\\International",
1129 KEY_READ
| KEY_WRITE
,
1131 if (ret
!= ERROR_SUCCESS
)
1136 dwSize
= 9 * sizeof(WCHAR
);
1137 ret
= RegQueryValueExW(hLocaleKey
,
1143 if (ret
!= ERROR_SUCCESS
)
1146 lcid
= (LCID
)wcstoul(szBuffer
, &ptr
, 16);
1151 while (LocaleData
[i
].pValue
!= NULL
)
1153 if (GetLocaleInfoW(lcid
,
1154 LocaleData
[i
].LCType
| LOCALE_NOUSEROVERRIDE
,
1156 ARRAYSIZE(szBuffer
)))
1158 RegSetValueExW(hLocaleKey
,
1159 LocaleData
[i
].pValue
,
1163 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1170 RegCloseKey(hLocaleKey
);
1176 SaveDefaultUserHive(VOID
)
1178 WCHAR szDefaultUserHive
[MAX_PATH
];
1179 HKEY hUserKey
= NULL
;
1183 DPRINT("SaveDefaultUserHive()\n");
1185 cchSize
= ARRAYSIZE(szDefaultUserHive
);
1186 GetDefaultUserProfileDirectoryW(szDefaultUserHive
, &cchSize
);
1188 wcscat(szDefaultUserHive
, L
"\\ntuser.dat");
1190 dwError
= RegOpenKeyExW(HKEY_USERS
,
1195 if (dwError
!= ERROR_SUCCESS
)
1197 DPRINT1("RegOpenKeyExW() failed (Error %lu)\n", dwError
);
1201 pSetupEnablePrivilege(L
"SeBackupPrivilege", TRUE
);
1203 dwError
= RegSaveKeyExW(hUserKey
,
1206 REG_STANDARD_FORMAT
);
1207 if (dwError
!= ERROR_SUCCESS
)
1209 DPRINT1("RegSaveKeyExW() failed (Error %lu)\n", dwError
);
1212 pSetupEnablePrivilege(L
"SeBackupPrivilege", FALSE
);
1214 RegCloseKey(hUserKey
);
1222 InstallReactOS(VOID
)
1224 WCHAR szBuffer
[MAX_PATH
];
1226 TOKEN_PRIVILEGES privs
;
1229 HANDLE hHotkeyThread
;
1232 InitializeSetupActionLog(FALSE
);
1233 LogItem(NULL
, L
"Installing ReactOS");
1235 CreateTempDir(L
"TEMP");
1236 CreateTempDir(L
"TMP");
1238 if (!InitializeProgramFilesDir())
1240 FatalError("InitializeProgramFilesDir() failed");
1244 if (!InitializeProfiles())
1246 FatalError("InitializeProfiles() failed");
1250 InitializeDefaultUserLocale();
1252 if (GetWindowsDirectoryW(szBuffer
, ARRAYSIZE(szBuffer
)))
1254 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1255 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
1258 &hKey
) == ERROR_SUCCESS
)
1260 RegSetValueExW(hKey
,
1265 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1267 RegSetValueExW(hKey
,
1272 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1277 PathAddBackslash(szBuffer
);
1278 wcscat(szBuffer
, L
"system");
1279 CreateDirectory(szBuffer
, NULL
);
1282 SaveDefaultUserHive();
1284 hHotkeyThread
= CreateThread(NULL
, 0, HotkeyThread
, NULL
, 0, NULL
);
1286 /* Hack: Install TCP/IP protocol driver */
1287 ret
= InstallInfSection(NULL
,
1289 L
"MS_TCPIP.PrimaryInstall",
1290 L
"MS_TCPIP.PrimaryInstall.Services");
1291 if (!ret
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
1293 DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError());
1297 /* Start the TCP/IP protocol driver */
1298 SetupStartService(L
"Tcpip", FALSE
);
1299 SetupStartService(L
"Dhcp", FALSE
);
1303 if (!CommonInstall())
1310 SetAutoAdminLogon();
1312 hShortcutsInf
= SetupOpenInfFileW(L
"shortcuts.inf",
1316 if (hShortcutsInf
== INVALID_HANDLE_VALUE
)
1318 FatalError("Failed to open shortcuts.inf");
1322 if (!CreateShortcuts(hShortcutsInf
, L
"ShortcutFolders"))
1324 FatalError("CreateShortcuts() failed");
1328 SetupCloseInfFile(hShortcutsInf
);
1330 hShortcutsInf
= SetupOpenInfFileW(L
"rosapps_shortcuts.inf",
1334 if (hShortcutsInf
!= INVALID_HANDLE_VALUE
)
1336 if (!CreateShortcuts(hShortcutsInf
, L
"ShortcutFolders"))
1338 FatalError("CreateShortcuts(rosapps) failed");
1341 SetupCloseInfFile(hShortcutsInf
);
1344 SetupCloseInfFile(hSysSetupInf
);
1349 PostThreadMessage(GetThreadId(hHotkeyThread
), WM_QUIT
, 0, 0);
1350 CloseHandle(hHotkeyThread
);
1353 LogItem(NULL
, L
"Installing ReactOS done");
1354 TerminateSetupActionLog();
1356 if (AdminInfo
.Name
!= NULL
)
1357 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Name
);
1359 if (AdminInfo
.Domain
!= NULL
)
1360 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Domain
);
1362 if (AdminInfo
.Password
!= NULL
)
1363 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Password
);
1365 /* Get shutdown privilege */
1366 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1368 FatalError("OpenProcessToken() failed!");
1371 if (!LookupPrivilegeValue(NULL
,
1373 &privs
.Privileges
[0].Luid
))
1375 FatalError("LookupPrivilegeValue() failed!");
1378 privs
.PrivilegeCount
= 1;
1379 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1380 if (AdjustTokenPrivileges(token
,
1384 (PTOKEN_PRIVILEGES
)NULL
,
1387 FatalError("AdjustTokenPrivileges() failed!");
1391 ExitWindowsEx(EWX_REBOOT
, 0);
1397 * Standard Windows-compatible export, which dispatches
1398 * to either 'InstallReactOS' or 'InstallLiveCD'.
1402 InstallWindowsNt(INT argc
, WCHAR
** argv
)
1407 for (i
= 0; i
< argc
; ++i
)
1414 // NOTE: On Windows, "mini" means "minimal UI", and can be used
1415 // in addition to "newsetup"; these options are not exclusive.
1416 if (_wcsicmp(p
, L
"newsetup") == 0)
1417 return (INT
)InstallReactOS();
1418 else if (_wcsicmp(p
, L
"mini") == 0)
1419 return (INT
)InstallLiveCD();
1421 /* Add support for other switches */
1433 SetupChangeFontSize(
1435 IN LPCWSTR lpszFontSize
)
1437 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1445 SetupChangeLocaleEx(HWND hWnd
,
1447 LPCWSTR lpSrcRootPath
,
1452 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1460 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1462 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);
1469 LPCWSTR lpServiceName
,
1472 SC_HANDLE hManager
= NULL
;
1473 SC_HANDLE hService
= NULL
;
1474 DWORD dwError
= ERROR_SUCCESS
;
1476 hManager
= OpenSCManagerW(NULL
,
1478 SC_MANAGER_ALL_ACCESS
);
1479 if (hManager
== NULL
)
1481 dwError
= GetLastError();
1485 hService
= OpenServiceW(hManager
,
1488 if (hService
== NULL
)
1490 dwError
= GetLastError();
1494 if (!StartService(hService
, 0, NULL
))
1496 dwError
= GetLastError();
1501 if (hService
!= NULL
)
1502 CloseServiceHandle(hService
);
1504 if (hManager
!= NULL
)
1505 CloseServiceHandle(hManager
);