Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1600 lines
52 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: CompChck.cpp
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: This module contains win32 only conponents checking and installing
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: Fengsun Created 10/21/97
  12. //
  13. //+----------------------------------------------------------------------------
  14. /////////////////////////////////////////////////////////////////////
  15. //
  16. // All the functions in this file are WIN32 implementation only
  17. //
  18. #include "cmmaster.h"
  19. #include "CompChck.h"
  20. #include "cmexitwin.cpp"
  21. #include "winuserp.h"
  22. //
  23. // CSDVersion key contains the service pack that has been installed
  24. //
  25. const TCHAR* const c_pszRegRas = TEXT("SOFTWARE\\Microsoft\\RAS");
  26. const TCHAR* const c_pszCheckComponentsMutex = TEXT("Connection Manager Components Checking");
  27. const TCHAR* const c_pszRegComponentsChecked = TEXT("ComponentsChecked");
  28. const CHAR* const c_pszSetupPPTPCommand = "rundll.exe rnasetup.dll,InstallOptionalComponent VPN"; // not using TEXT macro, this is W98+ only
  29. //
  30. // Functions internal to this file
  31. //
  32. static HRESULT CheckComponents(HWND hWndParent, LPCTSTR pszServiceName, DWORD dwComponentsToCheck, OUT DWORD& dwComponentsMissed,
  33. BOOL fIgnoreRegKey, BOOL fUnattended );
  34. static BOOL InstallComponents(DWORD dwComponentsToInstall, HWND hWndParent, LPCTSTR pszServiceName);
  35. static BOOL MarkComponentsChecked(DWORD dwComponentsChecked);
  36. static BOOL ReadComponentsChecked(LPDWORD pdwComponentsChecked);
  37. static BOOL IsPPTPInstalled(void);
  38. static BOOL InstallPPTP(void);
  39. static BOOL IsScriptingInstalled(void);
  40. static HRESULT ConfigSystem(HWND hwndParent,
  41. DWORD dwfOptions,
  42. LPBOOL pbReboot);
  43. static HRESULT InetNeedSystemComponents(DWORD dwfOptions,
  44. LPBOOL pbNeedSysComponents);
  45. static HRESULT InetNeedModem(LPBOOL pbNeedModem);
  46. static void DisplayMessageToInstallServicePack(HWND hWndParent, LPCTSTR pszServiceName);
  47. static inline HINSTANCE LoadInetCfg(void)
  48. {
  49. return (LoadLibraryExA("cnetcfg.dll", NULL, 0));
  50. }
  51. //+----------------------------------------------------------------------------
  52. //
  53. // Function IsPPTPInstalled
  54. //
  55. // Synopsis Check to see if PPTP is already installed
  56. //
  57. // Arguments None
  58. //
  59. // Returns TRUE - PPTP has been installed
  60. // FALSE - otherwise
  61. //
  62. // History 3/25/97 VetriV Created
  63. //
  64. //-----------------------------------------------------------------------------
  65. BOOL IsPPTPInstalled(void)
  66. {
  67. BOOL bReturnCode = FALSE;
  68. HKEY hKey = NULL;
  69. DWORD dwSize = 0, dwType = 0;
  70. LONG lrc = 0;
  71. TCHAR szData[MAX_PATH+1];
  72. if (OS_NT)
  73. {
  74. if (GetOSMajorVersion() >= 5)
  75. {
  76. //
  77. // PPTP is always installed on NT5
  78. //
  79. bReturnCode = TRUE;
  80. }
  81. else
  82. {
  83. if (RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  84. TEXT("SOFTWARE\\Microsoft\\RASPPTP"),
  85. 0,
  86. KEY_READ,
  87. &hKey) == 0)
  88. {
  89. RegCloseKey(hKey);
  90. bReturnCode = TRUE;
  91. }
  92. }
  93. }
  94. else
  95. {
  96. hKey = NULL;
  97. lrc = RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  98. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\OptionalComponents\\VPN"),
  99. 0,
  100. KEY_READ,
  101. &hKey);
  102. if (ERROR_SUCCESS == lrc)
  103. {
  104. dwSize = MAX_PATH;
  105. lrc = RegQueryValueExU(hKey, TEXT("Installed"), 0,
  106. &dwType, (LPBYTE)szData, &dwSize);
  107. if (ERROR_SUCCESS == lrc)
  108. {
  109. if (0 == lstrcmpiU(szData, TEXT("1")))
  110. {
  111. //
  112. // On 9X, we need to check for Dial-Up Adapter #2. If its
  113. // not present then tunneling won't work unless we install
  114. // PPTP to install the Adapter #2.
  115. //
  116. //
  117. // On early versions of Win9x Dial-up Adapter was localized, but on WinME, WinSE,
  118. // or machines that have DUN 1.3 installed it isn't. Thus, lets try the unlocalized
  119. // first and then if that fails we can try the localized version.
  120. //
  121. const TCHAR * const c_pszDialupAdapter = TEXT("Dial-up Adapter");
  122. LPTSTR pszAdapter = NULL;
  123. LPTSTR pszKey = CmStrCpyAlloc(TEXT("System\\CurrentControlSet\\Control\\PerfStats\\Enum\\"));
  124. CmStrCatAlloc(&pszKey, c_pszDialupAdapter);
  125. CmStrCatAlloc(&pszKey, TEXT(" #2"));
  126. //
  127. // Close the key that we opened above, and try the one for the adapter
  128. //
  129. RegCloseKey(hKey);
  130. hKey = NULL;
  131. if (ERROR_SUCCESS == RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  132. pszKey,
  133. 0,
  134. KEY_QUERY_VALUE,
  135. &hKey))
  136. {
  137. bReturnCode = TRUE;
  138. }
  139. else
  140. {
  141. CmFree (pszKey);
  142. pszAdapter = CmLoadString(g_hInst, IDS_REG_DIALUP_ADAPTER);
  143. pszKey = CmStrCpyAlloc(TEXT("System\\CurrentControlSet\\Control\\PerfStats\\Enum\\"));
  144. CmStrCatAlloc(&pszKey, pszAdapter);
  145. CmStrCatAlloc(&pszKey, TEXT(" #2"));
  146. //
  147. // Close the key that we opened above, and try the one for the adapter
  148. //
  149. RegCloseKey(hKey);
  150. hKey = NULL;
  151. if (ERROR_SUCCESS == RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  152. pszKey,
  153. 0,
  154. KEY_QUERY_VALUE,
  155. &hKey))
  156. {
  157. bReturnCode = TRUE;
  158. }
  159. }
  160. CmFree(pszKey);
  161. CmFree(pszAdapter);
  162. }
  163. }
  164. }
  165. if (hKey)
  166. {
  167. RegCloseKey(hKey);
  168. hKey = NULL;
  169. }
  170. }
  171. return bReturnCode;
  172. }
  173. //+----------------------------------------------------------------------------
  174. //
  175. // Function InstallPPTP
  176. //
  177. // Synopsis Install PPTP on Windows 95 and NT
  178. //
  179. // Arguments None
  180. //
  181. // Returns TRUE -- if was successfully installed
  182. // FALSE -- Otherwise
  183. //
  184. // History 3/25/97 VetriV Created
  185. // 7/8/97 VetriV Added code to setup PPTP on Memphis
  186. //
  187. //-----------------------------------------------------------------------------
  188. BOOL InstallPPTP(void)
  189. {
  190. BOOL bReturnCode = FALSE;
  191. MSG msg ;
  192. if (OS_NT || OS_W95)
  193. {
  194. //
  195. // Don't know how to install/configure PPTP on NT.
  196. // We let the admin wrestle with MSDUNXX on W95
  197. //
  198. return FALSE;
  199. }
  200. else
  201. {
  202. CHAR szCommand[128];
  203. STARTUPINFOA si;
  204. PROCESS_INFORMATION pi;
  205. ZeroMemory(&pi, sizeof(pi));
  206. ZeroMemory(&si, sizeof(si));
  207. si.cb = sizeof(STARTUPINFOA);
  208. //
  209. // NOTE: The original version called "msdun12.exe /q /R:N" to install tunneling
  210. // on Windows 95. Now we use 98 approach only and call the following:
  211. // "rundll.exe rnasetup.dll,InstallOptionalComponent VPN".
  212. //
  213. MYDBGASSERT(1353 < LOWORD(GetOSBuildNumber()));
  214. MYDBGASSERT(OS_W98); // based on the if clause above. The following code (A calls instead of W or U) also depends on this
  215. CHAR szRundllLocation[MAX_PATH + 11 + 1]; // 11 = length of "\\rundll.exe"
  216. (void) GetWindowsDirectoryA(szRundllLocation, MAX_PATH);
  217. lstrcatA(szRundllLocation, "\\rundll.exe");
  218. lstrcpyA(szCommand, c_pszSetupPPTPCommand);
  219. if (NULL == CreateProcessA(szRundllLocation, szCommand,
  220. NULL, NULL, FALSE, 0,
  221. NULL, NULL, &si, &pi))
  222. {
  223. CMTRACE1(TEXT("InstallPPTP() CreateProcess() failed, GLE=%u."), GetLastError());
  224. }
  225. else
  226. {
  227. CMTRACE(TEXT("InstallPPTP() Launched PPTP Install. Waiting for exit."));
  228. //
  229. // wait for event or msgs. Dispatch msgs. Exit when event is signalled.
  230. //
  231. while((MsgWaitForMultipleObjects(1, &pi.hProcess,
  232. FALSE, INFINITE,
  233. QS_ALLINPUT) == (WAIT_OBJECT_0 + 1)))
  234. {
  235. //
  236. // read all of the messages in this next loop
  237. // removing each message as we read it
  238. //
  239. while (PeekMessageU(&msg, NULL, 0, 0, PM_REMOVE))
  240. {
  241. CMTRACE(TEXT("InstallPPTP() Got Message"));
  242. //
  243. // how to handle quit message?
  244. //
  245. DispatchMessageU(&msg);
  246. if (msg.message == WM_QUIT)
  247. {
  248. CMTRACE(TEXT("InstallPPTP() Got Quit Message"));
  249. goto done;
  250. }
  251. }
  252. }
  253. done:
  254. CloseHandle(pi.hThread);
  255. CloseHandle(pi.hProcess);
  256. //
  257. // PPTP was successfully installed
  258. //
  259. bReturnCode = TRUE;
  260. CMTRACE(TEXT("InstallPPTP() done"));
  261. }
  262. }
  263. return bReturnCode;
  264. }
  265. //+----------------------------------------------------------------------------
  266. //
  267. // Function IsMSDUN12Installed
  268. //
  269. // Synopsis Check if MSDUN 1.2 or higher is installed.
  270. //
  271. // Arguments none
  272. //
  273. // Returns TRUE - MSDUN 1.2 is installed
  274. //
  275. // History 8/12/97 nickball from ICW for 11900
  276. //
  277. //-----------------------------------------------------------------------------
  278. #define DUN_12_Version "1.2"
  279. BOOL IsMSDUN12Installed()
  280. {
  281. CHAR szBuffer[MAX_PATH] = {"\0"};
  282. HKEY hkey = NULL;
  283. BOOL bRC = FALSE;
  284. DWORD dwType = 0;
  285. DWORD dwSize = sizeof(szBuffer);
  286. //
  287. // Try to open the Version key
  288. //
  289. if (ERROR_SUCCESS != RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  290. "System\\CurrentControlSet\\Services\\RemoteAccess",
  291. 0,
  292. KEY_READ,
  293. &hkey))
  294. {
  295. return FALSE;
  296. }
  297. //
  298. // The key exists, check the value
  299. //
  300. if (ERROR_SUCCESS == RegQueryValueExA(hkey, "Version", NULL, &dwType,
  301. (LPBYTE)szBuffer, &dwSize))
  302. {
  303. //
  304. // If the entry starts with "1.2", (eg. "1.2c") its a hit
  305. //
  306. bRC = (szBuffer == CmStrStrA(szBuffer, DUN_12_Version));
  307. }
  308. RegCloseKey(hkey);
  309. return bRC;
  310. }
  311. //+----------------------------------------------------------------------------
  312. //
  313. // Function IsISDN11Installed
  314. //
  315. // Synopsis Check if ISDN 1.1 is installed
  316. //
  317. // Arguments none
  318. //
  319. // Returns TRUE - ISDN 1.1 is installed
  320. //
  321. // Note: MSDUN12 superscedes ISDN1.1, but ISDN1.1 does provide scripting
  322. //
  323. // History 8/12/97 nickball
  324. //
  325. //-----------------------------------------------------------------------------
  326. BOOL IsISDN11Installed()
  327. {
  328. CHAR szBuffer[MAX_PATH] = {"\0"};
  329. HKEY hkey = NULL;
  330. BOOL bRC = FALSE;
  331. DWORD dwType = 0;
  332. DWORD dwSize = sizeof(szBuffer);
  333. if (ERROR_SUCCESS != RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  334. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OptionalComponents\\MSISDN",
  335. 0,
  336. KEY_READ,
  337. &hkey))
  338. {
  339. goto IsISDN11InstalledExit;
  340. }
  341. if (ERROR_SUCCESS != RegQueryValueExA(hkey,
  342. "Installed",
  343. NULL,
  344. &dwType,
  345. (LPBYTE)szBuffer,
  346. &dwSize))
  347. {
  348. goto IsISDN11InstalledExit;
  349. }
  350. if (0 == lstrcmpA("1", szBuffer))
  351. {
  352. bRC = TRUE;
  353. }
  354. IsISDN11InstalledExit:
  355. return bRC;
  356. }
  357. //+----------------------------------------------------------------------------
  358. //
  359. // Function IsScriptingInstalled
  360. //
  361. // Synopsis Check to see if scripting is already installed
  362. //
  363. // Arguments None
  364. //
  365. // Returns TRUE - scripting has been installed
  366. //
  367. // History 3/5/97 VetriV From ICW code
  368. //
  369. //-----------------------------------------------------------------------------
  370. BOOL IsScriptingInstalled(void)
  371. {
  372. BOOL bReturnCode = FALSE;
  373. HKEY hkey = NULL;
  374. DWORD dwSize = 0, dwType = 0;
  375. LONG lrc = 0;
  376. HINSTANCE hInst = NULL;
  377. CHAR szData[MAX_PATH+1];
  378. if (OS_NT)
  379. {
  380. //
  381. // NT comes with Scripting installed
  382. //
  383. bReturnCode = TRUE;
  384. }
  385. else
  386. {
  387. //
  388. // OSR2 and higher releases of Windows 95 have scripting installed
  389. //
  390. if (1111 <= LOWORD(GetOSBuildNumber()))
  391. {
  392. bReturnCode = TRUE;
  393. }
  394. else
  395. {
  396. //
  397. // Must be Gold 95, check for installed scripting
  398. //
  399. if (IsMSDUN12Installed() || IsISDN11Installed())
  400. {
  401. bReturnCode = TRUE;
  402. }
  403. else
  404. {
  405. hkey = NULL;
  406. lrc = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  407. "System\\CurrentControlSet\\Services\\RemoteAccess\\Authentication\\SMM_FILES\\PPP",
  408. 0,
  409. KEY_READ,
  410. &hkey);
  411. if (ERROR_SUCCESS == lrc)
  412. {
  413. dwSize = MAX_PATH;
  414. lrc = RegQueryValueExA(hkey, "Path", 0, &dwType, (LPBYTE)szData, &dwSize);
  415. if (ERROR_SUCCESS == lrc)
  416. {
  417. if (0 == CmCompareStringA(szData,"smmscrpt.dll"))
  418. {
  419. bReturnCode = TRUE;
  420. }
  421. }
  422. }
  423. if (hkey)
  424. {
  425. RegCloseKey(hkey);
  426. hkey = NULL;
  427. }
  428. //
  429. // Verify that the DLL can be loaded
  430. //
  431. if (bReturnCode)
  432. {
  433. hInst = LoadLibraryExA("smmscrpt.dll", NULL, 0);
  434. if (hInst)
  435. {
  436. FreeLibrary(hInst);
  437. }
  438. else
  439. {
  440. bReturnCode = FALSE;
  441. }
  442. hInst = NULL;
  443. }
  444. }
  445. }
  446. }
  447. return bReturnCode;
  448. }
  449. //+----------------------------------------------------------------------------
  450. // Function VerifyRasServicesRunning
  451. //
  452. // Synopsis Make sure that the RAS services are enabled and running
  453. //
  454. // Arguments hWndDlg: - Window Handle of parent window
  455. // pszServiceName - Service name for titles
  456. // fUnattended: - if TRUE, do not do not popup any UI
  457. //
  458. // Return FALSE - if the services couldn't be started
  459. //
  460. // History 2/26/97 VetriV Copied from ICW code
  461. //-----------------------------------------------------------------------------
  462. BOOL VerifyRasServicesRunning(HWND hWndDlg, LPCTSTR pszServiceName, BOOL fUnattended)
  463. {
  464. BOOL bReturnCode = FALSE;
  465. HINSTANCE hInstance = NULL;
  466. HRESULT (WINAPI *pfn)(void);
  467. hInstance = LoadInetCfg();
  468. if (!hInstance)
  469. {
  470. CMTRACE1(TEXT("VerifyRasServicesRunning() LoadLibrary() failed, GLE=%u."), GetLastError());
  471. }
  472. else
  473. {
  474. pfn = (HRESULT (WINAPI *)(void))GetProcAddress(hInstance, "InetStartServices");
  475. if (pfn)
  476. {
  477. LPTSTR pszDisabledMsg;
  478. LPTSTR pszExitMsg;
  479. pszDisabledMsg = CmFmtMsg(g_hInst, IDS_SERVICEDISABLED);
  480. pszExitMsg = CmFmtMsg(g_hInst, IDS_WANTTOEXIT);
  481. //
  482. // Check RAS Services
  483. //
  484. do
  485. {
  486. HRESULT hr = pfn();
  487. if (ERROR_SUCCESS == hr)
  488. {
  489. bReturnCode = TRUE;
  490. break;
  491. }
  492. else
  493. {
  494. CMTRACE1(TEXT("VerifyRasServicesRunning() InetStartServices() failed, GLE=%u."), hr);
  495. }
  496. //
  497. // Do not retry if unattended
  498. //
  499. if (!fUnattended)
  500. {
  501. bReturnCode = FALSE;
  502. break;
  503. }
  504. //
  505. // Check the error code of OpenService
  506. // Do not ask user to retry for certain errors
  507. //
  508. if (hr == ERROR_SERVICE_DOES_NOT_EXIST || hr == ERROR_FILE_NOT_FOUND ||
  509. hr == ERROR_ACCESS_DENIED)
  510. {
  511. LPTSTR pszNotInstalledMsg = CmFmtMsg(g_hInst, IDS_SERVICENOTINSTALLED);
  512. //
  513. // Report the error and Exit
  514. //
  515. MessageBoxEx(hWndDlg, pszNotInstalledMsg, pszServiceName,
  516. MB_OK|MB_ICONSTOP,
  517. LANG_USER_DEFAULT);
  518. CmFree(pszNotInstalledMsg);
  519. bReturnCode = FALSE;
  520. break;
  521. }
  522. //
  523. // Report the error and allow the user to retry
  524. //
  525. if (IDYES != MessageBoxEx(hWndDlg,pszDisabledMsg,pszServiceName,
  526. MB_YESNO | MB_DEFBUTTON1
  527. | MB_ICONWARNING,
  528. LANG_USER_DEFAULT))
  529. {
  530. //
  531. // Confirm Exit
  532. //
  533. if (IDYES == MessageBoxEx(hWndDlg, pszExitMsg, pszServiceName,
  534. MB_APPLMODAL | MB_ICONQUESTION
  535. | MB_YESNO | MB_DEFBUTTON2,
  536. LANG_USER_DEFAULT))
  537. {
  538. bReturnCode = FALSE;
  539. break;
  540. }
  541. }
  542. } while (1);
  543. CmFree(pszDisabledMsg);
  544. CmFree(pszExitMsg);
  545. }
  546. else
  547. {
  548. CMTRACE1(TEXT("VerifyRasServicesRunning() GetProcAddress() failed, GLE=%u."), GetLastError());
  549. }
  550. FreeLibrary(hInstance);
  551. }
  552. return bReturnCode;
  553. }
  554. //+----------------------------------------------------------------------------
  555. // Function CheckAndInstallComponents
  556. //
  557. // Synopsis Make sure the system is setup for dialing
  558. //
  559. // Arguments dwComponentsToCheck - Components to be checked
  560. // hWndParent - Window Handle of parent window
  561. // pszServiceName - Long service name for error titles
  562. // fIgnoreRegKey: - Whether ignore ComponetsChecked registry key
  563. // Default is TRUE, check the components even if their bit is set
  564. // in registry
  565. // fUnattended: if TRUE, do not try to install missed components,
  566. // do not popup any UI
  567. // Defualt is FALSE, install.
  568. //
  569. // Return Other - if system could not be configured
  570. // or if the we have to reboot to continue
  571. // ERROR_SUCCESS - Check and install successfully
  572. //
  573. // History 3/13/97 VetriV
  574. // 6/24/97 byao Modified. Set pArgs->dwExitCode accordingly
  575. // 11/6/97 fengsun changed parameters, do not pass pArgs
  576. //-----------------------------------------------------------------------------
  577. DWORD CheckAndInstallComponents(DWORD dwComponentsToCheck, HWND hWndParent, LPCTSTR pszServiceName,
  578. BOOL fIgnoreRegKey, BOOL fUnattended)
  579. {
  580. MYDBGASSERT( (dwComponentsToCheck &
  581. ~(CC_RNA | CC_TCPIP | CC_MODEM | CC_PPTP | CC_SCRIPTING | CC_RASRUNNING | CC_CHECK_BINDINGS) ) == 0 );
  582. if (dwComponentsToCheck == 0)
  583. {
  584. return ERROR_SUCCESS;
  585. }
  586. //
  587. // Open the mutex, so only one CM instance can call this function.
  588. // The destructor of CNamedMutex will release the mutex
  589. //
  590. CNamedMutex theMutex;
  591. if (!theMutex.Lock(c_pszCheckComponentsMutex))
  592. {
  593. //
  594. // Another instance of cm is checking components. Return here
  595. //
  596. if (!fUnattended)
  597. {
  598. LPTSTR pszMsg = CmLoadString(g_hInst, IDMSG_COMPONENTS_CHECKING_INPROCESS);
  599. MessageBoxEx(hWndParent, pszMsg, pszServiceName, MB_OK | MB_ICONERROR, LANG_USER_DEFAULT);
  600. CmFree(pszMsg);
  601. }
  602. return ERROR_CANCELLED;
  603. }
  604. //
  605. // Find components missed
  606. //
  607. DWORD dwComponentsMissed = 0;
  608. DWORD dwRet = CheckComponents(hWndParent, pszServiceName, dwComponentsToCheck, dwComponentsMissed,
  609. fIgnoreRegKey, fUnattended);
  610. if (dwRet == ERROR_SUCCESS)
  611. {
  612. MYDBGASSERT(dwComponentsMissed == 0);
  613. return ERROR_SUCCESS;
  614. }
  615. if (dwRet == E_ACCESSDENIED && OS_NT5)
  616. {
  617. //
  618. // On NT5, non-admin user does not have access to check components
  619. // Continue.
  620. //
  621. return ERROR_SUCCESS;
  622. }
  623. if (fUnattended)
  624. {
  625. //
  626. // Do not try to install if fUnattended is TRUE
  627. //
  628. return dwRet;
  629. }
  630. if (dwComponentsMissed & ~CC_RASRUNNING)
  631. {
  632. //
  633. // Prompt user before configuring system
  634. // If modem is not installed, expilitly say that
  635. //
  636. LPTSTR pszMsg;
  637. if (dwComponentsMissed == CC_MODEM)
  638. {
  639. //
  640. // On NT4, if RAS is installed and modem is not installed or
  641. // not configured for dialout, then we cannot programmatically
  642. // install and configure modem for the user (limitation of NT RAS
  643. // install/configuration). So, we will display a message to user
  644. // to manually go and install and/or configure modem from NCPA
  645. //
  646. if (OS_NT4)
  647. {
  648. pszMsg = CmFmtMsg(g_hInst, IDMSG_INSTALLMODEM_MANUALLY_MSG);
  649. MessageBoxEx(hWndParent, pszMsg, pszServiceName,
  650. MB_OK | MB_ICONERROR,
  651. LANG_USER_DEFAULT);
  652. CmFree(pszMsg);
  653. return ERROR_CANCELLED;
  654. }
  655. else
  656. {
  657. pszMsg = CmFmtMsg(g_hInst, IDMSG_NOMODEM_MSG);
  658. }
  659. }
  660. else
  661. {
  662. pszMsg = CmFmtMsg(g_hInst, IDMSG_NORAS_MSG);
  663. }
  664. int iRes = MessageBoxEx(hWndParent, pszMsg, pszServiceName,
  665. MB_YESNO | MB_DEFBUTTON1 | MB_ICONWARNING,
  666. LANG_USER_DEFAULT);
  667. CmFree(pszMsg);
  668. if (IDYES != iRes)
  669. {
  670. return ERROR_CANCELLED;
  671. }
  672. if (!InstallComponents(dwComponentsMissed, hWndParent, pszServiceName))
  673. {
  674. //
  675. // Some time, GetLastError returns ERROR_SUCCESS
  676. //
  677. return (GetLastError() == ERROR_SUCCESS ? ERROR_CANCELLED : GetLastError());
  678. }
  679. }
  680. //
  681. // We can not do anything if RAS can not be started on NT
  682. //
  683. if (dwComponentsMissed & CC_RASRUNNING)
  684. {
  685. return dwRet;
  686. }
  687. else
  688. {
  689. return ERROR_SUCCESS;
  690. }
  691. }
  692. //+----------------------------------------------------------------------------
  693. // Function MarkComponentsChecked
  694. //
  695. // Synopsis Mark(in registry) what components have been checked.
  696. //
  697. // Arguments DWORD dwComponentsInstalled - a dword(bitwise OR'ed)
  698. //
  699. // Return TRUE - success
  700. // FALSE - otherwise
  701. //
  702. // History 08/07/97 Fengsun - created
  703. // 08/11/97 henryt - changed return type.
  704. // 07/03/98 nickball - create if can't open
  705. //-----------------------------------------------------------------------------
  706. BOOL MarkComponentsChecked(DWORD dwComponentsChecked)
  707. {
  708. HKEY hKeyCm;
  709. //
  710. // Try to open the key for writing
  711. //
  712. LONG lRes = RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  713. c_pszRegCmRoot,
  714. 0,
  715. KEY_SET_VALUE ,
  716. &hKeyCm);
  717. //
  718. // If we can't open it the key may not be there, try to create it.
  719. //
  720. if (ERROR_SUCCESS != lRes)
  721. {
  722. DWORD dwDisposition;
  723. lRes = RegCreateKeyExU(HKEY_LOCAL_MACHINE,
  724. c_pszRegCmRoot,
  725. 0,
  726. TEXT(""),
  727. REG_OPTION_NON_VOLATILE,
  728. KEY_SET_VALUE,
  729. NULL,
  730. &hKeyCm,
  731. &dwDisposition);
  732. }
  733. //
  734. // On success, update the ComponentsChecked value, then close
  735. //
  736. if (ERROR_SUCCESS == lRes)
  737. {
  738. lRes = RegSetValueExU(hKeyCm, c_pszRegComponentsChecked, NULL, REG_DWORD,
  739. (BYTE*)&dwComponentsChecked, sizeof(dwComponentsChecked));
  740. RegCloseKey(hKeyCm);
  741. }
  742. return (ERROR_SUCCESS == lRes);
  743. }
  744. //+----------------------------------------------------------------------------
  745. // Function ReadComponentsChecked
  746. //
  747. // Synopsis Read(from registry) what components have been checked.
  748. //
  749. // Arguments LPDWORD pdwComponentsInstalled - a ptr dword(bitwise OR'ed)
  750. //
  751. // Return TRUE - success
  752. // FALSE - otherwise
  753. //
  754. // History 8/7/97 fengsun original code
  755. // 8/11/97 henryt created the func.
  756. //-----------------------------------------------------------------------------
  757. BOOL ReadComponentsChecked(
  758. LPDWORD pdwComponentsChecked
  759. )
  760. {
  761. BOOL fSuccess = FALSE;
  762. HKEY hKeyCm;
  763. DWORD dwType;
  764. DWORD dwSize = sizeof(DWORD);
  765. *pdwComponentsChecked = 0;
  766. if (RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  767. c_pszRegCmRoot,
  768. 0,
  769. KEY_QUERY_VALUE ,
  770. &hKeyCm) == ERROR_SUCCESS)
  771. {
  772. if ((RegQueryValueExU(hKeyCm,
  773. c_pszRegComponentsChecked,
  774. NULL,
  775. &dwType,
  776. (BYTE*)pdwComponentsChecked,
  777. &dwSize) == ERROR_SUCCESS) &&
  778. (dwType == REG_DWORD) &&
  779. (dwSize == sizeof(DWORD)))
  780. {
  781. fSuccess = TRUE;
  782. }
  783. RegCloseKey(hKeyCm);
  784. }
  785. return fSuccess;
  786. }
  787. //+----------------------------------------------------------------------------
  788. //
  789. // Function: ClearComponentsChecked
  790. //
  791. // Synopsis: Clear the component checked flag in registry back to 0
  792. //
  793. // Arguments: None
  794. //
  795. // Returns: Nothing
  796. //
  797. // History: fengsun Created Header 2/19/98
  798. //
  799. //+----------------------------------------------------------------------------
  800. void ClearComponentsChecked()
  801. {
  802. MarkComponentsChecked(0);
  803. }
  804. //+----------------------------------------------------------------------------
  805. // Function CheckComponents
  806. //
  807. // Synopsis Checks to see if the system has all the components
  808. // required of the service profile (like PPTP, TCP,...)
  809. // installed and configured
  810. //
  811. // Arguments hWndParent -Window Handle of parent window
  812. // pszServiceName - Service Name for title
  813. // dwComponentsToCheck:- Components to check
  814. // dwComponentsMissed: - OUT components missed
  815. // fIgnoreRegKey: - Whether ignore ComponetsChecked registry key
  816. // Default is FALSE, not check the components whose bit is set
  817. // in registry
  818. // fUnattended: if TRUE, do not do not popup any UI
  819. //
  820. // Return ERROR_SUCCESS- system does not need configuration
  821. // Other - otherwise
  822. //
  823. // History 5/5/97 VetriV
  824. // 6/26/97 byao Modified: update pArgs->dwExitCode when
  825. // components needed
  826. // 8/11/97 henryt Performance changes. Added CC_* flags.
  827. // 9/30/97 henryt added pfPptpNotInstalled
  828. // 11/6/97 fengsun changed parameters, do not pass pArgs
  829. //-----------------------------------------------------------------------------
  830. HRESULT CheckComponents(HWND hWndParent, LPCTSTR pszServiceName, DWORD dwComponentsToCheck, OUT DWORD& dwComponentsMissed,
  831. BOOL fIgnoreRegKey, BOOL fUnattended )
  832. {
  833. DWORD dwComponentsAlreadyChecked = 0; // Components already checked, to be saved into registry
  834. ReadComponentsChecked(&dwComponentsAlreadyChecked);
  835. CMTRACE1(TEXT("CheckComponents: dwComponentsToCheck = 0x%x"), dwComponentsToCheck);
  836. CMTRACE1(TEXT("CheckComponents: dwComponentsAlreadyChecked = 0x%x"), dwComponentsAlreadyChecked);
  837. //
  838. // If this is NT4 and we have successfully checked RAS installation
  839. // previously, double-check by examining Reg key. We do this because
  840. // the user may have removed RAS since our last component check in
  841. // which case an unpleasant message is displayed to the user when
  842. // we try to load RASAPI32.DLL
  843. //
  844. if (dwComponentsAlreadyChecked & CC_RNA)
  845. {
  846. if (OS_NT4)
  847. {
  848. //
  849. // RAS was installed properly at some point, but if
  850. // we can't open the key, then mark it as un-checked.
  851. //
  852. HKEY hKeyCm;
  853. DWORD dwRes = RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  854. c_pszRegRas,
  855. 0,
  856. KEY_QUERY_VALUE ,
  857. &hKeyCm);
  858. if (ERROR_SUCCESS == dwRes)
  859. {
  860. RegCloseKey(hKeyCm);
  861. }
  862. else
  863. {
  864. dwComponentsAlreadyChecked &= ~CC_RNA;
  865. }
  866. }
  867. }
  868. if (!fIgnoreRegKey)
  869. {
  870. //
  871. // Do not check those components already marked as checked in the registry
  872. //
  873. dwComponentsToCheck &= ~dwComponentsAlreadyChecked;
  874. }
  875. CMTRACE1(TEXT("CheckComponents: Now only checking components = 0x%x"), dwComponentsToCheck);
  876. HRESULT hrRet = S_OK; // return value
  877. dwComponentsMissed = 0; // Components not installed
  878. //
  879. // Check for DUN and TCP
  880. //
  881. if (dwComponentsToCheck & (CC_RNA | CC_TCPIP | CC_CHECK_BINDINGS))
  882. {
  883. BOOL bNeedSystemComponents = FALSE;
  884. if (dwComponentsToCheck & CC_CHECK_BINDINGS)
  885. {
  886. //
  887. // If we to check if PPP is bound to TCP
  888. //
  889. hrRet = InetNeedSystemComponents(INETCFG_INSTALLRNA |
  890. INETCFG_INSTALLTCP,
  891. &bNeedSystemComponents);
  892. }
  893. else
  894. {
  895. //
  896. // If we do not want to check if TCP is bound (in case of shims)
  897. // check just if TCP is installed
  898. //
  899. hrRet = InetNeedSystemComponents(INETCFG_INSTALLRNA |
  900. INETCFG_INSTALLTCPONLY,
  901. &bNeedSystemComponents);
  902. }
  903. if ((FAILED(hrRet)) || (TRUE == bNeedSystemComponents))
  904. {
  905. //
  906. // Set the Missing components properly - RNA and/or TCP missing
  907. // whether binding is missing or not depends on
  908. // if CC_REVIEW_BINDINGS was set or not
  909. //
  910. dwComponentsMissed |= (CC_RNA | CC_TCPIP);
  911. if (dwComponentsToCheck & CC_CHECK_BINDINGS)
  912. {
  913. dwComponentsMissed |= CC_CHECK_BINDINGS;
  914. }
  915. if (SUCCEEDED(hrRet))
  916. {
  917. hrRet = HRESULT_FROM_WIN32(ERROR_PROTOCOL_NOT_CONFIGURED);
  918. }
  919. }
  920. }
  921. //
  922. // Check for Modem
  923. // Note: Should not even run the modem check is RNA is not installed
  924. //
  925. if (dwComponentsToCheck & CC_MODEM)
  926. {
  927. BOOL bNeedModem = FALSE;
  928. hrRet = InetNeedModem(&bNeedModem);
  929. if (FAILED(hrRet))
  930. {
  931. dwComponentsMissed |= (CC_MODEM | CC_RNA);
  932. }
  933. else
  934. {
  935. if (TRUE == bNeedModem)
  936. {
  937. dwComponentsMissed |= CC_MODEM;
  938. hrRet = HRESULT_FROM_WIN32(ERROR_PROTOCOL_NOT_CONFIGURED);
  939. }
  940. }
  941. }
  942. //
  943. // Check if PPTP is installed, IsPPTPInstalled always returns TRUE for NT5
  944. //
  945. if (dwComponentsToCheck & CC_PPTP)
  946. {
  947. if (FALSE == IsPPTPInstalled())
  948. {
  949. dwComponentsMissed |= CC_PPTP;
  950. hrRet = HRESULT_FROM_WIN32(ERROR_PROTOCOL_NOT_CONFIGURED);
  951. }
  952. }
  953. //
  954. // Check for scripting
  955. // if PPTP is installed then we have scripting also
  956. // - msdun12.exe (used to install PPTP on Win95 contains scripting)
  957. if (dwComponentsToCheck & CC_SCRIPTING)
  958. {
  959. if ((FALSE == IsScriptingInstalled()) && (FALSE == IsPPTPInstalled()))
  960. {
  961. dwComponentsMissed |= CC_SCRIPTING;
  962. hrRet = HRESULT_FROM_WIN32(ERROR_PROTOCOL_NOT_CONFIGURED);
  963. }
  964. }
  965. //
  966. // Check if RAS services are running
  967. // This is basically for NT4 and becomes a NOP on Windows 95 or NT5
  968. // On NT5, CM is started by Connection Folder. RAS is automaticlly
  969. // started when ConnFolder is launched or CM desktop icon is clicked. If RAS service
  970. // failed to launch, CM will not be execute at all.
  971. //
  972. if (OS_NT && (dwComponentsToCheck & CC_RASRUNNING))
  973. {
  974. if (FALSE == VerifyRasServicesRunning(hWndParent, pszServiceName, !fUnattended))
  975. {
  976. //
  977. // Don't let the user continue if RAS is not running
  978. //
  979. dwComponentsMissed |= CC_RASRUNNING;
  980. DWORD dwRet = ( GetLastError() == ERROR_SUCCESS )?
  981. ERROR_PROTOCOL_NOT_CONFIGURED : GetLastError();
  982. hrRet = HRESULT_FROM_WIN32(dwRet);
  983. }
  984. }
  985. //
  986. // Update the components already checked
  987. // Plus Components just checked, including those failed
  988. // Minus components missed
  989. //
  990. DWORD dwComponentsCheckedNew = (dwComponentsAlreadyChecked | dwComponentsToCheck) & ~dwComponentsMissed;
  991. //
  992. // Update only if there is some change
  993. //
  994. if (dwComponentsCheckedNew != dwComponentsAlreadyChecked)
  995. {
  996. MarkComponentsChecked(dwComponentsCheckedNew);
  997. }
  998. return hrRet;
  999. }
  1000. //+----------------------------------------------------------------------------
  1001. // Function InstallComponents
  1002. //
  1003. // Synopsis Installs all components required for the profile
  1004. // (PPTP, TCP, DUN, Modem,...)
  1005. //
  1006. // Arguments hWndDlg - Window Handle of parent window
  1007. // pszServiceName - Name of the service for title
  1008. // dwComponentsToInstall - Componets to install
  1009. //
  1010. // Return FALSE - if system could not be configured
  1011. // TRUE - otherwise
  1012. //
  1013. // History 3/13/97 VetriV Created
  1014. // 5/5/97 VetriV Renamed function as InstallComponents
  1015. // (used to be ConfigureSystemForDialing)
  1016. // 9/30/97 henryt added fInstallPptpOnly
  1017. // 11/6/97 fengsun changed parameters, do not pass pArgs
  1018. // 2/3/98 VetriV changed code to inform user to reinstall
  1019. // service pack if any component was installed
  1020. // by this function and user had some SP
  1021. // installed in the system
  1022. //-----------------------------------------------------------------------------
  1023. BOOL InstallComponents(DWORD dwComponentsToInstall, HWND hWndDlg, LPCTSTR pszServiceName)
  1024. {
  1025. //
  1026. // We are not allowed to configure the system at WinLogon because we have
  1027. // no idea who the user is. It could be just a random person walking up to the box.
  1028. //
  1029. if (!IsLogonAsSystem())
  1030. {
  1031. BOOL bReboot = FALSE;
  1032. CMTRACE1(TEXT("InstallComponents: dwComponentsToInstall = 0x%x"), dwComponentsToInstall);
  1033. //
  1034. // We can not do any thing if RAS is not running
  1035. //
  1036. MYDBGASSERT(!(dwComponentsToInstall & CC_RASRUNNING));
  1037. //
  1038. // Disable the window, and enable it on return
  1039. // The property sheet also need to be disabled
  1040. //
  1041. CFreezeWindow FreezeWindow(hWndDlg, TRUE);
  1042. DWORD hRes = ERROR_SUCCESS;
  1043. //
  1044. // Do not install modem here. Install modem after reboot
  1045. //
  1046. if (dwComponentsToInstall & (CC_RNA | CC_MODEM | INETCFG_INSTALLTCP | INETCFG_INSTALLTCPONLY))
  1047. {
  1048. DWORD dwInetComponent = 0;
  1049. dwInetComponent |= (dwComponentsToInstall & CC_RNA ? INETCFG_INSTALLRNA :0) |
  1050. (dwComponentsToInstall & CC_MODEM ? INETCFG_INSTALLMODEM :0);
  1051. //
  1052. // Only way to check bindings is by installing TCP
  1053. // This case will also cover the more common case of installing TCP
  1054. // and checking for bindings
  1055. //
  1056. if (CC_CHECK_BINDINGS & dwComponentsToInstall)
  1057. {
  1058. dwInetComponent |= INETCFG_INSTALLTCP;
  1059. }
  1060. else if (CC_TCPIP & dwComponentsToInstall)
  1061. {
  1062. //
  1063. // If bindings check is not turned on
  1064. //
  1065. dwInetComponent |= INETCFG_INSTALLTCPONLY;
  1066. }
  1067. if (dwInetComponent)
  1068. {
  1069. hRes = ConfigSystem(hWndDlg,dwInetComponent, &bReboot);
  1070. }
  1071. }
  1072. if (ERROR_SUCCESS == hRes)
  1073. {
  1074. //
  1075. // Check for scripting
  1076. // if PPTP is installed than we have scripting also
  1077. // - because msdun12.exe (used to install PPTP on Win95
  1078. // contains scripting)
  1079. // and install if it is needed
  1080. //
  1081. if ((dwComponentsToInstall & CC_SCRIPTING) &&
  1082. !(dwComponentsToInstall & CC_PPTP) )
  1083. {
  1084. LPTSTR pszNoScriptMsg = CmFmtMsg(g_hInst, IDMSG_NO_SCRIPT_INST_MSG_95);
  1085. if (pszNoScriptMsg)
  1086. {
  1087. MessageBoxEx(hWndDlg, pszNoScriptMsg, pszServiceName,
  1088. MB_OK | MB_ICONSTOP, LANG_USER_DEFAULT);
  1089. CmFree(pszNoScriptMsg);
  1090. }
  1091. return FALSE;
  1092. }
  1093. //
  1094. // Check if PPTP is required and not already installed install it
  1095. //
  1096. if (dwComponentsToInstall & CC_PPTP)
  1097. {
  1098. if (TRUE == InstallPPTP()) // Note: Always fails on 95 by design
  1099. {
  1100. //
  1101. // We have to reboot after installing PPTP
  1102. //
  1103. bReboot = TRUE;
  1104. }
  1105. else
  1106. {
  1107. LPTSTR pszMsg;
  1108. //
  1109. // Don't let the user continue PPTP is not installed
  1110. //
  1111. if (OS_NT)
  1112. {
  1113. if (IsServicePackInstalled())
  1114. {
  1115. //
  1116. // we need to tell the user to re-apply the service pack after manual
  1117. // install of PPTP.
  1118. //
  1119. pszMsg = CmFmtMsg(g_hInst, IDMSG_NOPPTPINST_MSG_NT_SP); // NT
  1120. }
  1121. else
  1122. {
  1123. pszMsg = CmFmtMsg(g_hInst, IDMSG_NOPPTPINST_MSG_NT); // NT
  1124. }
  1125. }
  1126. else if (OS_W98)
  1127. {
  1128. pszMsg = CmFmtMsg(g_hInst, IDMSG_NOPPTPINST_MSG_98); // W98
  1129. }
  1130. else
  1131. {
  1132. pszMsg = CmFmtMsg(g_hInst, IDMSG_NOPPTPINST_MSG_95); // default
  1133. }
  1134. if (pszMsg)
  1135. {
  1136. MessageBoxEx(hWndDlg, pszMsg, pszServiceName,
  1137. MB_OK | MB_ICONSTOP, LANG_USER_DEFAULT);
  1138. CmFree(pszMsg);
  1139. }
  1140. return FALSE;
  1141. }
  1142. }
  1143. }
  1144. if ((ERROR_SUCCESS == hRes) && bReboot)
  1145. {
  1146. if (OS_NT && (TRUE == IsServicePackInstalled()))
  1147. {
  1148. //
  1149. // If service pack is installed, then display message asking
  1150. // user to re-install the service pack and exit without rebooting
  1151. // We do this because rebooting after installing RAS, without
  1152. // reinstalling the service pack can cause BlueScreen!
  1153. //
  1154. DisplayMessageToInstallServicePack(hWndDlg, pszServiceName);
  1155. return FALSE;
  1156. }
  1157. else
  1158. {
  1159. //
  1160. // Display reboot message and is user wants reboot the sytem
  1161. //
  1162. LPTSTR pszMsg = CmFmtMsg(g_hInst,IDMSG_REBOOT_MSG);
  1163. int iRes = IDNO;
  1164. if (pszMsg)
  1165. {
  1166. iRes = MessageBoxEx(hWndDlg,
  1167. pszMsg,
  1168. pszServiceName,
  1169. MB_YESNO | MB_DEFBUTTON1 |
  1170. MB_ICONWARNING | MB_SETFOREGROUND,
  1171. LANG_USER_DEFAULT);
  1172. CmFree(pszMsg);
  1173. }
  1174. else
  1175. {
  1176. CMASSERTMSG(FALSE, TEXT("InstallComponents: CmFmtMsg failed to load IDMSG_REBOOT_MSG"));
  1177. }
  1178. if (IDYES == iRes)
  1179. {
  1180. //
  1181. // Shutdown Windows, CM will quit gracefully on
  1182. // WM_ENDSESSION message
  1183. // What shall we do if MyExitWindowsEx() fialed
  1184. //
  1185. DWORD dwReason = OS_NT51 ? (SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_RECONFIG) : 0;
  1186. MyExitWindowsEx(EWX_REBOOT, dwReason);
  1187. //
  1188. // Caller will return failed
  1189. //
  1190. return FALSE;
  1191. }
  1192. else
  1193. {
  1194. //
  1195. // If user do not want to reboot, shall we quit CM
  1196. //
  1197. }
  1198. }
  1199. }
  1200. if (ERROR_SUCCESS == hRes)
  1201. {
  1202. return TRUE;
  1203. }
  1204. }
  1205. //
  1206. // Configuration check failed message, if install is not canceled
  1207. //
  1208. LPTSTR pszMsg = CmFmtMsg(g_hInst,IDMSG_CONFIG_FAILED_MSG);
  1209. if (pszMsg)
  1210. {
  1211. MessageBoxEx(hWndDlg, pszMsg, pszServiceName, MB_OK|MB_ICONSTOP,
  1212. LANG_USER_DEFAULT);
  1213. CmFree(pszMsg);
  1214. }
  1215. else
  1216. {
  1217. CMASSERTMSG(FALSE, TEXT("InstallComponents: CmFmtMsg failed to load IDMSG_CONFIG_FAILED_MSG"));
  1218. }
  1219. return FALSE;
  1220. }
  1221. //+----------------------------------------------------------------------------
  1222. // Function ConfigSystem
  1223. //
  1224. // Synopsis Use inetcfg.dll to configure system settings,
  1225. // like install modem, rna etc.
  1226. //
  1227. // Arguments hWndDlg - Window Handle of parent window
  1228. // dwfOptions - Components to be configured
  1229. // pbReboot - Will be set to true if system has to rebooted
  1230. // as result of the configuration
  1231. //
  1232. // Returns ERROR_SUCCESS if successful
  1233. // Failure code otherwise
  1234. //
  1235. // History Old code
  1236. //-----------------------------------------------------------------------------
  1237. HRESULT ConfigSystem(HWND hwndParent,
  1238. DWORD dwfOptions,
  1239. LPBOOL pbReboot)
  1240. {
  1241. HRESULT hRes = ERROR_SUCCESS;
  1242. HINSTANCE hLibrary = NULL;
  1243. HRESULT (WINAPI *pfn)(HWND,DWORD,LPBOOL);
  1244. hLibrary = LoadInetCfg();
  1245. if (!hLibrary)
  1246. {
  1247. CMTRACE1(TEXT("ConfigSystem() LoadLibrary() failed, GLE=%u."), GetLastError());
  1248. hRes = GetLastError();
  1249. goto done;
  1250. }
  1251. pfn = (HRESULT (WINAPI *)(HWND,DWORD,LPBOOL)) GetProcAddress(hLibrary, "InetConfigSystem");
  1252. if (!pfn)
  1253. {
  1254. CMTRACE1(TEXT("ConfigSystem() GetProcAddress() failed, GLE=%u."), GetLastError());
  1255. hRes = GetLastError();
  1256. goto done;
  1257. }
  1258. hRes = pfn(hwndParent,dwfOptions,pbReboot);
  1259. #ifdef DEBUG
  1260. if (hRes != ERROR_SUCCESS)
  1261. {
  1262. CMTRACE1(TEXT("ConfigSystem() InetConfigSystem() failed, GLE=%u."), hRes);
  1263. }
  1264. #endif
  1265. done:
  1266. if (hLibrary)
  1267. {
  1268. FreeLibrary(hLibrary);
  1269. hLibrary = NULL;
  1270. }
  1271. return (hRes);
  1272. }
  1273. //+----------------------------------------------------------------------------
  1274. // Function InetNeedSystemComponents
  1275. //
  1276. // Synopsis Use inetcfg.dll to check if we need to configure system settings
  1277. // like rna etc.
  1278. //
  1279. // Arguments dwfOptions - Components to be configured
  1280. // pbNeedSysComponents - Will be set to true if we need to
  1281. // configure system settings
  1282. //
  1283. // Returns ERROR_SUCCESS if successful
  1284. // Failure code otherwise
  1285. //
  1286. // History 5/5/97 VetriV Created
  1287. //-----------------------------------------------------------------------------
  1288. HRESULT InetNeedSystemComponents(DWORD dwfOptions,
  1289. LPBOOL pbNeedSysComponents)
  1290. {
  1291. HRESULT hRes = ERROR_SUCCESS;
  1292. HINSTANCE hLibrary = NULL;
  1293. HRESULT (WINAPI *pfnInetNeedSystemComponents)(DWORD, LPBOOL);
  1294. hLibrary = LoadInetCfg();
  1295. if (!hLibrary)
  1296. {
  1297. hRes = GetLastError();
  1298. CMTRACE1(TEXT("InetNeedSystemComponents() LoadLibrary() failed, GLE=%u."), hRes);
  1299. goto done;
  1300. }
  1301. pfnInetNeedSystemComponents = (HRESULT (WINAPI *)(DWORD,LPBOOL)) GetProcAddress(hLibrary, "InetNeedSystemComponents");
  1302. if (!pfnInetNeedSystemComponents)
  1303. {
  1304. hRes = GetLastError();
  1305. CMTRACE1(TEXT("InetNeedSystemComponents() GetProcAddress() failed, GLE=%u."), hRes);
  1306. goto done;
  1307. }
  1308. hRes = pfnInetNeedSystemComponents(dwfOptions, pbNeedSysComponents);
  1309. #ifdef DEBUG
  1310. if (hRes != ERROR_SUCCESS)
  1311. {
  1312. CMTRACE1(TEXT("InetNeedSystemComponents() failed, GLE=%u."), hRes);
  1313. }
  1314. #endif
  1315. done:
  1316. if (hLibrary)
  1317. {
  1318. FreeLibrary(hLibrary);
  1319. hLibrary = NULL;
  1320. }
  1321. return (hRes);
  1322. }
  1323. //+----------------------------------------------------------------------------
  1324. // Function InetNeedModem
  1325. //
  1326. // Synopsis Use inetcfg.dll to check if we need to install/configure modem
  1327. //
  1328. // Arguments pbNeedModem - Will be set to true if we need to
  1329. // install/configure modem
  1330. //
  1331. // Returns ERROR_SUCCESS if successful
  1332. // Failure code otherwise
  1333. //
  1334. // History 5/5/97 VetriV Created
  1335. //-----------------------------------------------------------------------------
  1336. HRESULT InetNeedModem(LPBOOL pbNeedModem)
  1337. {
  1338. HRESULT hRes = ERROR_SUCCESS;
  1339. HINSTANCE hLibrary = NULL;
  1340. HRESULT (WINAPI *pfnInetNeedModem)(LPBOOL);
  1341. hLibrary = LoadInetCfg();
  1342. if (!hLibrary)
  1343. {
  1344. hRes = GetLastError();
  1345. CMTRACE1(TEXT("InetNeedModem() LoadLibrary() failed, GLE=%u."), hRes);
  1346. goto done;
  1347. }
  1348. pfnInetNeedModem = (HRESULT (WINAPI *)(LPBOOL)) GetProcAddress(hLibrary, "InetNeedModem");
  1349. if (!pfnInetNeedModem)
  1350. {
  1351. hRes = GetLastError();
  1352. CMTRACE1(TEXT("InetNeedModem() GetProcAddress() failed, GLE=%u."), hRes);
  1353. goto done;
  1354. }
  1355. hRes = pfnInetNeedModem(pbNeedModem);
  1356. #ifdef DEBUG
  1357. if (hRes != ERROR_SUCCESS)
  1358. {
  1359. CMTRACE1(TEXT("InetNeedModem() failed, GLE=%u."), hRes);
  1360. }
  1361. #endif
  1362. done:
  1363. if (hLibrary)
  1364. {
  1365. FreeLibrary(hLibrary);
  1366. hLibrary = NULL;
  1367. }
  1368. return (hRes);
  1369. }
  1370. //+----------------------------------------------------------------------------
  1371. // Function DisplayMessageToInstallServicePack
  1372. //
  1373. // Synopsis Display a message to user informing them to reinstall
  1374. // Service Pack
  1375. //
  1376. // Arguments hWndParent - Window handle to parent
  1377. // pszServiceName - Service name for title
  1378. //
  1379. // Returns None
  1380. //
  1381. // History 2/4/98 VetriV Created
  1382. //-----------------------------------------------------------------------------
  1383. void DisplayMessageToInstallServicePack(HWND hWndParent, LPCTSTR pszServiceName)
  1384. {
  1385. LPTSTR pszMsg = CmFmtMsg(g_hInst,IDMSG_INSTALLSP_MSG);
  1386. if (pszMsg)
  1387. {
  1388. MessageBoxEx(hWndParent, pszMsg, pszServiceName, MB_OK | MB_ICONINFORMATION,
  1389. LANG_USER_DEFAULT);
  1390. CmFree(pszMsg);
  1391. }
  1392. else
  1393. {
  1394. CMASSERTMSG(FALSE, TEXT("DisplayMessageToInstallServicePack: CmFmtMsg failed to load IDMSG_INSTALLSP_MSG"));
  1395. }
  1396. return;
  1397. }