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.

4362 lines
138 KiB

  1. //*******************************************************************
  2. //
  3. // Copyright(c) Microsoft Corporation, 1996
  4. //
  5. // FILE: EXPORT.C
  6. //
  7. // PURPOSE: Contains external API's for use by signup wizard.
  8. //
  9. // HISTORY:
  10. // 96/03/05 markdu Created.
  11. // 96/03/11 markdu Added InetConfigClient()
  12. // 96/03/11 markdu Added InetGetAutodial() and InetSetAutodial().
  13. // 96/03/12 markdu Added UI during file install.
  14. // 96/03/12 markdu Added ValidateConnectoidData().
  15. // 96/03/12 markdu Set connectoid for autodial if INETCFG_SETASAUTODIAL
  16. // is set. Renamed ValidateConnectoidData to MakeConnectoid.
  17. // 96/03/12 markdu Added hwnd param to InetConfigClient() and
  18. // InetConfigSystem().
  19. // 96/03/13 markdu Added INETCFG_OVERWRITEENTRY. Create unique neame
  20. // for connectoid if it already exists and we can't overwrite.
  21. // 96/03/13 markdu Added InstallTCPAndRNA().
  22. // 96/03/13 markdu Added LPINETCLIENTINFO param to InetConfigClient()
  23. // 96/03/16 markdu Added INETCFG_INSTALLMODEM flag.
  24. // 96/03/16 markdu Use ReInit member function to re-enumerate modems.
  25. // 96/03/19 markdu Split export.h into export.h and csexport.h
  26. // 96/03/20 markdu Combined export.h and iclient.h into inetcfg.h
  27. // 96/03/23 markdu Replaced CLIENTINFO references with CLIENTCONFIG.
  28. // 96/03/24 markdu Replaced lstrcpy with lstrcpyn where appropriate.
  29. // 96/03/25 markdu Validate lpfNeedsRestart before using.
  30. // 96/03/25 markdu Clean up some error handling.
  31. // 96/03/26 markdu Use MAX_ISP_NAME instead of RAS_MaxEntryName
  32. // because of bug in RNA.
  33. // 96/03/26 markdu Implemented UpdateMailSettings().
  34. // 96/03/27 mmaclin InetGetProxy()and InetSetProxy().
  35. // 96/04/04 markdu NASH BUG 15610 Check for file and printer sharing
  36. // bound to TCP/IP .
  37. // 96/04/04 markdu Added phonebook name param to InetConfigClient,
  38. // MakeConnectoid, SetConnectoidUsername, CreateConnectoid,
  39. // and ValidateConnectoidName.
  40. // 96/04/05 markdu Set internet icon on desktop to point to browser.
  41. // 96/04/06 mmaclin Changed InetSetProxy to check for NULL.
  42. // 96/04/06 markdu NASH BUG 16404 Initialize gpWizardState in
  43. // UpdateMailSettings.
  44. // 96/04/06 markdu NASH BUG 16441 If InetSetAutodial is called with NULL
  45. // as the connection name, the entry is not changed.
  46. // 96/04/18 markdu NASH BUG 18443 Make exports WINAPI.
  47. // 96/04/19 markdu NASH BUG 18605 Handle ERROR_FILE_NOT_FOUND return
  48. // from ValidateConnectoidName.
  49. // 96/04/19 markdu NASH BUG 17760 Do not show choose profile UI.
  50. // 96/04/22 markdu NASH BUG 18901 Do not set desktop internet icon to
  51. // browser if we are just creating a temp connectoid.
  52. // 96/04/23 markdu NASH BUG 18719 Make the choose profile dialog TOPMOST.
  53. // 96/04/25 markdu NASH BUG 19572 Only show choose profile dialog if
  54. // there is an existing profile.
  55. // 96/04/29 markdu NASH BUG 20003 Added InetConfigSystemFromPath
  56. // and removed InstallTCPAndRNA.
  57. // 96/05/01 markdu NASH BUG 20483 Do not display "installing files" dialog
  58. // if INETCFG_SUPPRESSINSTALLUI is set.
  59. // 96/05/01 markdu ICW BUG 8049 Reboot if modem is installed. This is
  60. // required because sometimes the configuration manager does not
  61. // set up the modem correctly, and the user will not be able to
  62. // dial (will get cryptic error message) until reboot.
  63. // 96/05/06 markdu NASH BUG 21027 If DNS is set globally, clear it out so
  64. // the per-connectoid settings will be saved.
  65. // 96/05/14 markdu NASH BUG 21706 Removed BigFont functions.
  66. // 96/05/25 markdu Use ICFG_ flags for lpNeedDrivers and lpInstallDrivers.
  67. // 96/05/27 markdu Use lpIcfgInstallInetComponents and lpIcfgNeedInetComponents.
  68. // 96/05/28 markdu Moved InitConfig and DeInitConfig to DllEntryPoint.
  69. // 96/10/21 valdonb Added CheckConnectionWizard and InetCreateMailNewsAccount
  70. //
  71. //*******************************************************************
  72. #include "wizard.h"
  73. #include "inetcfg.h"
  74. #include "icwextsn.h"
  75. #include <icwcfg.h>
  76. // constants
  77. #define LEN_APPEND_INT 3 // number of digits for MAX_APPEND_INT
  78. #define MAX_APPEND_INT 999 // maximum number to append to connectoid name // when cycling through names to create unique name
  79. #pragma data_seg(".rdata")
  80. // Registry constants
  81. static const TCHAR cszRegPathInternetSettings[] = REGSTR_PATH_INTERNET_SETTINGS;
  82. static const TCHAR cszRegPathInternetLanSettings[] = REGSTR_PATH_INTERNET_LAN_SETTINGS;
  83. static const TCHAR cszRegValProxyEnable[] = REGSTR_VAL_PROXYENABLE;
  84. static const TCHAR cszRegValProxyServer[] = REGSTR_VAL_PROXYSERVER;
  85. static const TCHAR cszRegValProxyOverride[] = REGSTR_VAL_PROXYOVERRIDE;
  86. static const TCHAR cszRegValAutoProxyDetectMode[] = TEXT("AutoProxyDetectMode");
  87. static const TCHAR cszRegValAutoConfigURL[] = TEXT("AutoConfigURL");
  88. static const TCHAR cszWininet[] = TEXT("WININET.DLL");
  89. static const CHAR cszInternetSetOption[] = "InternetSetOptionA";
  90. static const CHAR cszInternetQueryOption[] = "InternetQueryOptionA";
  91. #define REGSTR_PATH_TELEPHONYLOCATIONS REGSTR_PATH_SETUP TEXT("\\Telephony\\Locations")
  92. #pragma data_seg()
  93. // structure to pass data back from IDD_NEEDDRIVERS handler
  94. typedef struct tagNEEDDRIVERSDLGINFO
  95. {
  96. DWORD dwfOptions;
  97. LPBOOL lpfNeedsRestart;
  98. } NEEDDRIVERSDLGINFO, * PNEEDDRIVERSDLGINFO;
  99. // structure to pass data back from IDD_CHOOSEMODEMNAME handler
  100. typedef struct tagCHOOSEMODEMDLGINFO
  101. {
  102. TCHAR szModemName[RAS_MaxDeviceName + 1];
  103. } CHOOSEMODEMDLGINFO, * PCHOOSEMODEMDLGINFO;
  104. // structure to pass data back from IDD_CHOOSEPROFILENAME handler
  105. typedef struct tagCHOOSEPROFILEDLGINFO
  106. {
  107. TCHAR szProfileName[cchProfileNameMax+1];
  108. BOOL fSetProfileAsDefault;
  109. } CHOOSEPROFILEDLGINFO, * PCHOOSEPROFILEDLGINFO;
  110. // Function prototypes internal to this file
  111. HRESULT UpdateMailSettings(HWND hwndParent, LPINETCLIENTINFO lpINetClientInfo,
  112. LPTSTR lpszEntryName);
  113. INT_PTR CALLBACK ChooseModemDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  114. LPARAM lParam);
  115. BOOL ChooseModemDlgInit(HWND hDlg,PCHOOSEMODEMDLGINFO pChooseModemDlgInfo);
  116. BOOL ChooseModemDlgOK(HWND hDlg,PCHOOSEMODEMDLGINFO pChooseModemDlgInfo);
  117. INT_PTR CALLBACK NeedDriversDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  118. LPARAM lParam);
  119. BOOL NeedDriversDlgInit(HWND hDlg,PNEEDDRIVERSDLGINFO pNeedDriversDlgInfo);
  120. int NeedDriversDlgOK(HWND hDlg,PNEEDDRIVERSDLGINFO pNeedDriversDlgInfo);
  121. VOID EnableDlg(HWND hDlg,BOOL fEnable);
  122. INT_PTR CALLBACK ChooseProfileDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  123. BOOL ChooseProfileDlgInit(HWND hDlg,CHOOSEPROFILEDLGINFO * pChooseProfileDlgInfo);
  124. BOOL ChooseProfileDlgOK(HWND hDlg,CHOOSEPROFILEDLGINFO * pChooseProfileDlgInfo);
  125. DWORD MakeConnectoid(
  126. HWND hwndParent,
  127. DWORD dwfOptions,
  128. LPCTSTR lpszPhonebook,
  129. LPCTSTR lpszEntryName,
  130. LPRASENTRY lpRasEntry,
  131. LPCTSTR lpszUsername,
  132. LPCTSTR lpszPassword,
  133. LPBOOL lpfNeedsRestart);
  134. HWND WaitCfgInit(HWND hwndParent, DWORD dwIDS);
  135. // Function prototypes external to this file
  136. VOID InitWizardState(WIZARDSTATE * pWizardState, DWORD dwFlags);
  137. BOOL DoNewProfileDlg(HWND hDlg);
  138. extern DWORD SetIEClientInfo(LPINETCLIENTINFO lpClientInfo);
  139. extern ICFGSETINSTALLSOURCEPATH lpIcfgSetInstallSourcePath;
  140. extern ICFGINSTALLSYSCOMPONENTS lpIcfgInstallInetComponents;
  141. extern ICFGNEEDSYSCOMPONENTS lpIcfgNeedInetComponents;
  142. extern ICFGGETLASTINSTALLERRORTEXT lpIcfgGetLastInstallErrorText;
  143. extern BOOL ValidateProductSuite(LPTSTR SuiteName);
  144. #ifdef UNICODE
  145. PWCHAR ToUnicodeWithAlloc(LPCSTR);
  146. VOID ToAnsiClientInfo(LPINETCLIENTINFOA, LPINETCLIENTINFOW);
  147. VOID ToUnicodeClientInfo(LPINETCLIENTINFOW, LPINETCLIENTINFOA);
  148. #endif
  149. //
  150. // from rnacall.cpp
  151. //
  152. extern BOOL InitTAPILocation(HWND hwndParent);
  153. #define SMART_RUNICW TRUE
  154. #define SMART_QUITICW FALSE
  155. #include "wininet.h"
  156. typedef BOOL (WINAPI * INTERNETSETOPTION) (IN HINTERNET hInternet OPTIONAL,IN DWORD dwOption,IN LPVOID lpBuffer,IN DWORD dwBufferLength);
  157. typedef BOOL (WINAPI * INTERNETQUERYOPTION) (IN HINTERNET hInternet OPTIONAL,IN DWORD dwOption,IN LPVOID lpBuffer,IN LPDWORD dwBufferLength);
  158. static const TCHAR g_szRegPathICWSettings[] = TEXT("Software\\Microsoft\\Internet Connection Wizard");
  159. static const TCHAR g_szRegValICWCompleted[] = TEXT("Completed");
  160. BOOL g_bUseAutoProxyforConnectoid = TRUE;
  161. //*******************************************************************
  162. //
  163. // FUNCTION: InetConfigSystem
  164. //
  165. // PURPOSE: This function will install files that are needed
  166. // for internet access (such as TCP/IP and RNA) based
  167. // the state of the options flags.
  168. //
  169. // PARAMETERS: hwndParent - window handle of calling application. This
  170. // handle will be used as the parent for any dialogs that
  171. // are required for error messages or the "installing files"
  172. // dialog.
  173. // dwfOptions - a combination of INETCFG_ flags that controls
  174. // the installation and configuration as follows:
  175. //
  176. // INETCFG_INSTALLMAIL - install exchange and internet mail
  177. // INETCFG_INSTALLMODEM - Invoke InstallModem wizard if NO
  178. // MODEM IS INSTALLED.
  179. // INETCFG_INSTALLRNA - install RNA (if needed)
  180. // INETCFG_INSTALLTCP - install TCP/IP (if needed)
  181. // INETCFG_CONNECTOVERLAN - connecting with LAN (vs modem)
  182. // INETCFG_WARNIFSHARINGBOUND - Check if TCP/IP file sharing is
  183. // turned on, and warn user to turn
  184. // it off. Reboot is required if
  185. // the user turns it off.
  186. // INETCFG_REMOVEIFSHARINGBOUND - Check if TCP/IP file sharing is
  187. // turned on, and force user to turn
  188. // it off. If user does not want to
  189. // turn it off, return will be
  190. // ERROR_CANCELLED. Reboot is
  191. // required if the user turns it off.
  192. //
  193. // lpfNeedsRestart - if non-NULL, then on return, this will be
  194. // TRUE if windows must be restarted to complete the installation.
  195. //
  196. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  197. //
  198. // HISTORY:
  199. // 96/03/05 markdu Created.
  200. //
  201. //*******************************************************************
  202. extern "C" HRESULT WINAPI InetConfigSystem(
  203. HWND hwndParent,
  204. DWORD dwfOptions,
  205. LPBOOL lpfNeedsRestart)
  206. {
  207. DWORD dwRet = ERROR_SUCCESS;
  208. BOOL fNeedsRestart = FALSE; // Default to no reboot needed
  209. // 4/2/97 ChrisK Olympus 209
  210. HWND hwndWaitDlg = NULL;
  211. TCHAR szWindowTitle[255];
  212. BOOL bSleepNeeded = FALSE;
  213. /*
  214. We do this messy NT 5.0 hack because for the time being the
  215. NT 4.0 API call fails to kil off the modem wizard in NT 5.0
  216. , so we need to pretend we are like 9x
  217. In the future when this problem is corrected the origional code should
  218. prpoably be restored -- ALL references to this BOOL should be deleted.
  219. a-jaswed
  220. */
  221. BOOL bNT5NeedModem = FALSE;
  222. DEBUGMSG("export.c::InetConfigSystem()");
  223. // Validate the parent hwnd
  224. if (hwndParent && !IsWindow(hwndParent))
  225. {
  226. return ERROR_INVALID_PARAMETER;
  227. }
  228. // Set up the install options
  229. DWORD dwfInstallOptions = 0;
  230. if (dwfOptions & INETCFG_INSTALLTCP)
  231. {
  232. dwfInstallOptions |= ICFG_INSTALLTCP;
  233. }
  234. if (dwfOptions & INETCFG_INSTALLRNA)
  235. {
  236. dwfInstallOptions |= ICFG_INSTALLRAS;
  237. }
  238. if (dwfOptions & INETCFG_INSTALLMAIL)
  239. {
  240. dwfInstallOptions |= ICFG_INSTALLMAIL;
  241. }
  242. // see if we need to install drivers
  243. BOOL fNeedSysComponents = FALSE;
  244. // 4/2/97 ChrisK Olympus 209 Display busy dialog
  245. if (INETCFG_SHOWBUSYANIMATION == (dwfOptions & INETCFG_SHOWBUSYANIMATION))
  246. hwndWaitDlg = WaitCfgInit(hwndParent,IDS_WAITCHECKING);
  247. //
  248. // Kill Modem control panel if it's already running
  249. // 4/16/97 ChrisK Olympus 239
  250. // 6/9/97 jmazner moved this functionality from InvokeModemWizard
  251. szWindowTitle[0] = '\0';
  252. LoadSz(IDS_MODEM_WIZ_TITLE,szWindowTitle,255);
  253. HWND hwndModem = FindWindow(TEXT("#32770"),szWindowTitle);
  254. if (NULL != hwndModem)
  255. {
  256. // Close modem installation wizard
  257. PostMessage(hwndModem, WM_CLOSE, 0, 0);
  258. bSleepNeeded = TRUE;
  259. }
  260. // close modem control panel applet
  261. LoadSz(IDS_MODEM_CPL_TITLE,szWindowTitle,255);
  262. hwndModem = FindWindow(TEXT("#32770"),szWindowTitle);
  263. if (NULL != hwndModem)
  264. {
  265. PostMessage(hwndModem, WM_SYSCOMMAND,SC_CLOSE, 0);
  266. bSleepNeeded = TRUE;
  267. }
  268. if (bSleepNeeded)
  269. {
  270. Sleep(1000);
  271. }
  272. dwRet = lpIcfgNeedInetComponents(dwfInstallOptions, &fNeedSysComponents);
  273. if (ERROR_SUCCESS != dwRet)
  274. {
  275. TCHAR szErrorText[MAX_ERROR_TEXT+1]=TEXT("");
  276. // 4/2/97 ChrisK Olympus 209
  277. // Dismiss busy dialog
  278. if (NULL != hwndWaitDlg)
  279. {
  280. BringWindowToTop(hwndParent);
  281. DestroyWindow(hwndWaitDlg);
  282. hwndWaitDlg = NULL;
  283. }
  284. //
  285. // Get the text of the error message and display it.
  286. //
  287. if (lpIcfgGetLastInstallErrorText(szErrorText, MAX_ERROR_TEXT+1))
  288. {
  289. MsgBoxSz(NULL,szErrorText,MB_ICONEXCLAMATION,MB_OK);
  290. }
  291. return dwRet;
  292. }
  293. if (fNeedSysComponents)
  294. {
  295. // 4/2/97 ChrisK Olympus 209
  296. // if we are going to install something the busy dialog isn't needed
  297. if (NULL != hwndWaitDlg)
  298. {
  299. BringWindowToTop(hwndParent);
  300. ShowWindow(hwndWaitDlg,SW_HIDE);
  301. }
  302. if (dwfOptions & INETCFG_SUPPRESSINSTALLUI)
  303. {
  304. dwRet = lpIcfgInstallInetComponents(hwndParent, dwfInstallOptions, &fNeedsRestart);
  305. //
  306. // Display error message only if it failed due to something
  307. // other than user cancel
  308. //
  309. if ((ERROR_SUCCESS != dwRet) && (ERROR_CANCELLED != dwRet))
  310. {
  311. TCHAR szErrorText[MAX_ERROR_TEXT+1]=TEXT("");
  312. // Get the text of the error message and display it.
  313. if (lpIcfgGetLastInstallErrorText(szErrorText, MAX_ERROR_TEXT+1))
  314. {
  315. MsgBoxSz(NULL,szErrorText,MB_ICONEXCLAMATION,MB_OK);
  316. }
  317. }
  318. }
  319. else
  320. {
  321. // structure to pass to dialog to fill out
  322. NEEDDRIVERSDLGINFO NeedDriversDlgInfo;
  323. NeedDriversDlgInfo.dwfOptions = dwfInstallOptions;
  324. NeedDriversDlgInfo.lpfNeedsRestart = &fNeedsRestart;
  325. // Clear out the last error code so we can safely use it.
  326. SetLastError(ERROR_SUCCESS);
  327. // Display a dialog and allow the user to cancel install
  328. int iRet = (int)DialogBoxParam(ghInstance,MAKEINTRESOURCE(IDD_NEEDDRIVERS),hwndParent,
  329. NeedDriversDlgProc,(LPARAM) &NeedDriversDlgInfo);
  330. if (0 == iRet)
  331. {
  332. // user cancelled
  333. dwRet = ERROR_CANCELLED;
  334. }
  335. else if (-1 == iRet)
  336. {
  337. // an error occurred.
  338. dwRet = GetLastError();
  339. if (ERROR_SUCCESS == dwRet)
  340. {
  341. // Error occurred, but the error code was not set.
  342. dwRet = ERROR_INETCFG_UNKNOWN;
  343. }
  344. }
  345. }
  346. }
  347. if ( (ERROR_SUCCESS == dwRet) && (TRUE == IsNT()) && (dwfOptions & INETCFG_INSTALLMODEM))
  348. {
  349. BOOL bNeedModem = FALSE;
  350. if (NULL == lpIcfgNeedModem)
  351. {
  352. //
  353. // 4/2/97 ChrisK Olympus 209
  354. //
  355. if (NULL != hwndWaitDlg)
  356. {
  357. BringWindowToTop(hwndParent);
  358. DestroyWindow(hwndWaitDlg);
  359. hwndWaitDlg = NULL;
  360. }
  361. return ERROR_GEN_FAILURE;
  362. }
  363. //
  364. // 4/2/97 ChrisK Olympus 209
  365. // Show busy dialog here, this can take a few seconds
  366. //
  367. if (NULL != hwndWaitDlg)
  368. ShowWindow(hwndWaitDlg,SW_SHOW);
  369. dwRet = (*lpIcfgNeedModem)(0, &bNeedModem);
  370. if (ERROR_SUCCESS != dwRet)
  371. {
  372. //
  373. // 4/2/97 ChrisK Olympus 209
  374. //
  375. if (NULL != hwndWaitDlg)
  376. {
  377. BringWindowToTop(hwndParent);
  378. DestroyWindow(hwndWaitDlg);
  379. hwndWaitDlg = NULL;
  380. }
  381. return dwRet;
  382. }
  383. if (TRUE == bNeedModem)
  384. {
  385. if (IsNT5() == TRUE)
  386. {
  387. bNT5NeedModem = bNeedModem;
  388. }
  389. else
  390. {
  391. // 4/2/97 ChrisK Olympus 209
  392. if (NULL != hwndWaitDlg)
  393. {
  394. BringWindowToTop(hwndParent);
  395. DestroyWindow(hwndWaitDlg);
  396. hwndWaitDlg = NULL;
  397. }
  398. MsgBoxParam(hwndParent,IDS_ERRNoDialOutModem,MB_ICONERROR,MB_OK);
  399. return ERROR_GEN_FAILURE;
  400. }
  401. }
  402. //
  403. // 7/15/97 jmazner Olympus #6294
  404. // make sure TAPI location info is valid
  405. //
  406. if (!InitTAPILocation(hwndParent))
  407. {
  408. if (NULL != hwndWaitDlg)
  409. {
  410. BringWindowToTop(hwndParent);
  411. DestroyWindow(hwndWaitDlg);
  412. hwndWaitDlg = NULL;
  413. }
  414. return ERROR_CANCELLED;
  415. }
  416. }
  417. // 4/2/97 ChrisK Olympus 209
  418. if (NULL != hwndWaitDlg)
  419. {
  420. BringWindowToTop(hwndParent);
  421. ShowWindow(hwndWaitDlg,SW_HIDE);
  422. }
  423. // See if we are supposed to check if file sharing is turned on
  424. if (ERROR_SUCCESS == dwRet && !(ValidateProductSuite( TEXT("Small Business") )))
  425. {
  426. BOOL fNeedsRestartTmp = FALSE;
  427. if (dwfOptions & INETCFG_REMOVEIFSHARINGBOUND)
  428. {
  429. // Tell user that we cannot continue unless binding is removed.
  430. dwRet = RemoveIfServerBound(hwndParent,
  431. (dwfOptions & INETCFG_CONNECTOVERLAN)? INSTANCE_NETDRIVER : INSTANCE_PPPDRIVER, &fNeedsRestartTmp);
  432. }
  433. else if (dwfOptions & INETCFG_WARNIFSHARINGBOUND)
  434. {
  435. // Warn user that binding should be removed.
  436. dwRet = WarnIfServerBound(hwndParent,
  437. (dwfOptions & INETCFG_CONNECTOVERLAN)?INSTANCE_NETDRIVER : INSTANCE_PPPDRIVER, &fNeedsRestartTmp);
  438. }
  439. // If the settings were removed, we need to reboot.
  440. if ((ERROR_SUCCESS == dwRet) && (TRUE == fNeedsRestartTmp))
  441. {
  442. fNeedsRestart = TRUE;
  443. }
  444. // If user installed net component but we need cancel F&P sharing, we still need to restart
  445. // or NT becomes unstable - Bug 68641
  446. if(ERROR_CANCELLED == dwRet && fNeedsRestart && IsNT())
  447. dwRet = ERROR_SUCCESS;
  448. }
  449. // 4/2/97 ChrisK Olympus 209
  450. // Dismiss dialog for good
  451. if (NULL != hwndWaitDlg)
  452. {
  453. BringWindowToTop(hwndParent);
  454. DestroyWindow(hwndWaitDlg);
  455. hwndWaitDlg = NULL;
  456. }
  457. //
  458. // If not NT then we install the modem after installing RAS
  459. //
  460. // See if we are supposed to install a modem
  461. if (((FALSE == IsNT()) || (bNT5NeedModem)) && (ERROR_SUCCESS == dwRet) &&
  462. (dwfOptions & INETCFG_INSTALLMODEM))
  463. {
  464. // Load RNA if not already loaded since ENUM_MODEM needs it.
  465. dwRet = EnsureRNALoaded();
  466. if (ERROR_SUCCESS != dwRet)
  467. {
  468. return dwRet;
  469. }
  470. // Enumerate the modems
  471. ENUM_MODEM EnumModem;
  472. dwRet = EnumModem.GetError();
  473. if (ERROR_SUCCESS != dwRet)
  474. {
  475. return dwRet;
  476. }
  477. // If there are no modems, install one if requested.
  478. if (0 == EnumModem.GetNumDevices())
  479. {
  480. //
  481. // 5/22/97 jmazner Olympus #4698
  482. // On Win95, calling RasEnumDevices launches RNAAP.EXE
  483. // If RNAAP.EXE is running, any modems you install won't be usable
  484. // So, nuke RNAAP.EXE before installing the modem.
  485. //
  486. TCHAR szWindowTitle[255] = TEXT("\0nogood");
  487. //
  488. // Unload the RAS dll's before killing RNAAP, just to be safe
  489. //
  490. DeInitRNA();
  491. LoadSz(IDS_RNAAP_TITLE,szWindowTitle,255);
  492. HWND hwnd = FindWindow(szWindowTitle, NULL);
  493. if (NULL != hwnd)
  494. {
  495. if (!PostMessage(hwnd, WM_CLOSE, 0, 0))
  496. {
  497. DEBUGMSG("Trying to kill RNAAP window returned getError %d", GetLastError());
  498. }
  499. }
  500. // invoke the modem wizard UI to install the modem
  501. UINT uRet = InvokeModemWizard(hwndParent);
  502. if (ERROR_PRIVILEGE_NOT_HELD == uRet)
  503. {
  504. TCHAR szAdminDenied [MAX_PATH] = TEXT("\0");
  505. LoadSz(IDS_ADMIN_ACCESS_DENIED, szAdminDenied, MAX_PATH);
  506. MsgBoxSz(hwndParent,szAdminDenied,MB_ICONEXCLAMATION,MB_OK);
  507. return ERROR_CANCELLED;
  508. }
  509. else if (uRet != ERROR_SUCCESS)
  510. {
  511. DisplayErrorMessage(hwndParent,IDS_ERRInstallModem,uRet,
  512. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  513. return ERROR_INVALID_PARAMETER;
  514. }
  515. // Reload the RAS dlls now that the modem has been safely installed.
  516. InitRNA(hwndParent);
  517. // Re-numerate the modems to be sure we have the most recent changes
  518. dwRet = EnumModem.ReInit();
  519. if (ERROR_SUCCESS != dwRet)
  520. {
  521. return dwRet;
  522. }
  523. // If there are still no modems, user cancelled
  524. if (0 == EnumModem.GetNumDevices())
  525. {
  526. return ERROR_CANCELLED;
  527. }
  528. else
  529. {
  530. // removed per GeoffR request 5-2-97
  531. //// 96/05/01 markdu ICW BUG 8049 Reboot if modem is installed.
  532. //fNeedsRestart = TRUE;
  533. }
  534. }
  535. else
  536. {
  537. //
  538. // 7/15/97 jmazner Olympus #6294
  539. // make sure TAPI location info is valid
  540. //
  541. // 4/15/99 vyung Tapi changed the location dlg
  542. if (!InitTAPILocation(hwndParent))
  543. {
  544. if (NULL != hwndWaitDlg)
  545. {
  546. BringWindowToTop(hwndParent);
  547. DestroyWindow(hwndWaitDlg);
  548. hwndWaitDlg = NULL;
  549. }
  550. return ERROR_CANCELLED;
  551. }
  552. }
  553. }
  554. // tell caller whether we need to reboot or not
  555. if ((ERROR_SUCCESS == dwRet) && (lpfNeedsRestart))
  556. {
  557. *lpfNeedsRestart = fNeedsRestart;
  558. }
  559. // 4/2/97 ChrisK Olympus 209
  560. // Sanity check
  561. if (NULL != hwndWaitDlg)
  562. {
  563. BringWindowToTop(hwndParent);
  564. DestroyWindow(hwndWaitDlg);
  565. hwndWaitDlg = NULL;
  566. }
  567. return dwRet;
  568. }
  569. //*******************************************************************
  570. //
  571. // FUNCTION: InetNeedSystemComponents
  572. //
  573. // PURPOSE: This function will check is components that are needed
  574. // for internet access (such as TCP/IP and RNA) are already
  575. // configured based the state of the options flags.
  576. //
  577. // PARAMETERS: dwfOptions - a combination of INETCFG_ flags that controls
  578. // the installation and configuration as follows:
  579. //
  580. // INETCFG_INSTALLRNA - install RNA (if needed)
  581. // INETCFG_INSTALLTCP - install TCP/IP (if needed)
  582. //
  583. // lpfNeedsConfig - On return, this will be
  584. // TRUE if system component(s)
  585. // should be installed
  586. //
  587. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  588. //
  589. // HISTORY: 05/02/97 VetriV Created.
  590. // 05/08/97 ChrisK Added INSTALLLAN, INSTALLDIALUP, and
  591. // INSTALLTCPONLY
  592. //
  593. //*******************************************************************
  594. extern "C" HRESULT WINAPI InetNeedSystemComponents(DWORD dwfOptions,
  595. LPBOOL lpbNeedsConfig)
  596. {
  597. DWORD dwRet = ERROR_SUCCESS;
  598. DEBUGMSG("export.cpp::InetNeedSystemComponents()");
  599. //
  600. // Validate parameters
  601. //
  602. if (!lpbNeedsConfig)
  603. {
  604. return ERROR_INVALID_PARAMETER;
  605. }
  606. //
  607. // Set up the install options
  608. //
  609. DWORD dwfInstallOptions = 0;
  610. if (dwfOptions & INETCFG_INSTALLTCP)
  611. {
  612. dwfInstallOptions |= ICFG_INSTALLTCP;
  613. }
  614. if (dwfOptions & INETCFG_INSTALLRNA)
  615. {
  616. dwfInstallOptions |= ICFG_INSTALLRAS;
  617. }
  618. //
  619. // ChrisK 5/8/97
  620. //
  621. if (dwfOptions & INETCFG_INSTALLLAN)
  622. {
  623. dwfInstallOptions |= ICFG_INSTALLLAN;
  624. }
  625. if (dwfOptions & INETCFG_INSTALLDIALUP)
  626. {
  627. dwfInstallOptions |= ICFG_INSTALLDIALUP;
  628. }
  629. if (dwfOptions & INETCFG_INSTALLTCPONLY)
  630. {
  631. dwfInstallOptions |= ICFG_INSTALLTCPONLY;
  632. }
  633. //
  634. // see if we need to install drivers
  635. //
  636. BOOL bNeedSysComponents = FALSE;
  637. dwRet = lpIcfgNeedInetComponents(dwfInstallOptions, &bNeedSysComponents);
  638. if (ERROR_SUCCESS != dwRet)
  639. {
  640. TCHAR szErrorText[MAX_ERROR_TEXT+1]=TEXT("");
  641. //
  642. // Get the text of the error message and display it.
  643. //
  644. if (lpIcfgGetLastInstallErrorText(szErrorText, MAX_ERROR_TEXT+1))
  645. {
  646. DEBUGMSG(szErrorText);
  647. }
  648. return dwRet;
  649. }
  650. *lpbNeedsConfig = bNeedSysComponents;
  651. return ERROR_SUCCESS;
  652. }
  653. //*******************************************************************
  654. //
  655. // FUNCTION: InetNeedModem
  656. //
  657. // PURPOSE: This function will check if modem is needed or not
  658. //
  659. // PARAMETERS: lpfNeedsConfig - On return, this will be
  660. // TRUE if modem
  661. // should be installed
  662. //
  663. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  664. //
  665. // HISTORY: 05/02/97 VetriV Created.
  666. //
  667. //*******************************************************************
  668. extern "C" HRESULT WINAPI InetNeedModem(LPBOOL lpbNeedsModem)
  669. {
  670. DWORD dwRet = ERROR_SUCCESS;
  671. //
  672. // Validate parameters
  673. //
  674. if (!lpbNeedsModem)
  675. {
  676. return ERROR_INVALID_PARAMETER;
  677. }
  678. if (TRUE == IsNT())
  679. {
  680. //
  681. // On NT call icfgnt.dll to determine if modem is needed
  682. //
  683. BOOL bNeedModem = FALSE;
  684. if (NULL == lpIcfgNeedModem)
  685. {
  686. return ERROR_GEN_FAILURE;
  687. }
  688. dwRet = (*lpIcfgNeedModem)(0, &bNeedModem);
  689. if (ERROR_SUCCESS != dwRet)
  690. {
  691. return dwRet;
  692. }
  693. *lpbNeedsModem = bNeedModem;
  694. return ERROR_SUCCESS;
  695. }
  696. else
  697. {
  698. //
  699. // Load RNA if not already loaded since ENUM_MODEM needs it.
  700. //
  701. dwRet = EnsureRNALoaded();
  702. if (ERROR_SUCCESS != dwRet)
  703. {
  704. return dwRet;
  705. }
  706. //
  707. // Enumerate the modems
  708. //
  709. ENUM_MODEM EnumModem;
  710. dwRet = EnumModem.GetError();
  711. if (ERROR_SUCCESS != dwRet)
  712. {
  713. return dwRet;
  714. }
  715. //
  716. // If there are no modems, we need to install one
  717. //
  718. if (0 == EnumModem.GetNumDevices())
  719. {
  720. *lpbNeedsModem = TRUE;
  721. }
  722. else
  723. {
  724. *lpbNeedsModem = FALSE;
  725. }
  726. return ERROR_SUCCESS;
  727. }
  728. }
  729. //*******************************************************************
  730. //
  731. // FUNCTION: InetConfigSystemFromPath
  732. //
  733. // PURPOSE: This function will install files that are needed
  734. // for internet access (such as TCP/IP and RNA) based
  735. // the state of the options flags and from the given [ath.
  736. //
  737. // PARAMETERS: hwndParent - window handle of calling application. This
  738. // handle will be used as the parent for any dialogs that
  739. // are required for error messages or the "installing files"
  740. // dialog.
  741. // dwfOptions - a combination of INETCFG_ flags that controls
  742. // the installation and configuration as follows:
  743. //
  744. // INETCFG_INSTALLMAIL - install exchange and internet mail
  745. // INETCFG_INSTALLMODEM - Invoke InstallModem wizard if NO
  746. // MODEM IS INSTALLED.
  747. // INETCFG_INSTALLRNA - install RNA (if needed)
  748. // INETCFG_INSTALLTCP - install TCP/IP (if needed)
  749. // INETCFG_CONNECTOVERLAN - connecting with LAN (vs modem)
  750. // INETCFG_WARNIFSHARINGBOUND - Check if TCP/IP file sharing is
  751. // turned on, and warn user to turn
  752. // it off. Reboot is required if
  753. // the user turns it off.
  754. // INETCFG_REMOVEIFSHARINGBOUND - Check if TCP/IP file sharing is
  755. // turned on, and force user to turn
  756. // it off. If user does not want to
  757. // turn it off, return will be
  758. // ERROR_CANCELLED. Reboot is
  759. // required if the user turns it off.
  760. //
  761. // lpfNeedsRestart - if non-NULL, then on return, this will be
  762. // TRUE if windows must be restarted to complete the installation.
  763. // lpszSourcePath - full path of location of files to install. If
  764. // this is NULL, default path is used.
  765. //
  766. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  767. //
  768. // HISTORY:
  769. // 96/04/29 markdu Created.
  770. //
  771. //*******************************************************************
  772. #ifdef UNICODE
  773. HRESULT WINAPI InetConfigSystemFromPathA
  774. (
  775. HWND hwndParent,
  776. DWORD dwfOptions,
  777. LPBOOL lpfNeedsRestart,
  778. LPCSTR lpszSourcePath
  779. )
  780. {
  781. TCHAR szSourcePath[MAX_PATH+1];
  782. mbstowcs(szSourcePath, lpszSourcePath, lstrlenA(lpszSourcePath)+1);
  783. return InetConfigSystemFromPathW(hwndParent, dwfOptions,
  784. lpfNeedsRestart, szSourcePath);
  785. }
  786. HRESULT WINAPI InetConfigSystemFromPathW
  787. #else
  788. HRESULT WINAPI InetConfigSystemFromPathA
  789. #endif
  790. (
  791. HWND hwndParent,
  792. DWORD dwfOptions,
  793. LPBOOL lpfNeedsRestart,
  794. LPCTSTR lpszSourcePath
  795. )
  796. {
  797. DWORD dwRet;
  798. DEBUGMSG("export.c::InetConfigSystemFromPath()");
  799. // Validate the parent hwnd
  800. if (hwndParent && !IsWindow(hwndParent))
  801. {
  802. return ERROR_INVALID_PARAMETER;
  803. }
  804. // Set the install path here
  805. if (lpszSourcePath && lstrlen(lpszSourcePath))
  806. {
  807. dwRet = lpIcfgSetInstallSourcePath(lpszSourcePath);
  808. if (ERROR_SUCCESS != dwRet)
  809. {
  810. return dwRet;
  811. }
  812. }
  813. // Install files if needed.
  814. dwRet = InetConfigSystem(hwndParent,
  815. dwfOptions, lpfNeedsRestart);
  816. return dwRet;
  817. }
  818. //*******************************************************************
  819. //
  820. // FUNCTION: InetConfigClient
  821. //
  822. // PURPOSE: This function requires a valid phone book entry name
  823. // (unless it is being used just to set the client info).
  824. // If lpRasEntry points to a valid RASENTRY struct, the phone
  825. // book entry will be created (or updated if it already exists)
  826. // with the data in the struct.
  827. // If username and password are given, these
  828. // will be set as the dial params for the phone book entry.
  829. // If a client info struct is given, that data will be set.
  830. // Any files (ie TCP and RNA) that are needed will be
  831. // installed by calling InetConfigSystem().
  832. // This function will also perform verification on the device
  833. // specified in the RASENTRY struct. If no device is specified,
  834. // the user will be prompted to install one if there are none
  835. // installed, or they will be prompted to choose one if there
  836. // is more than one installed.
  837. //
  838. // PARAMETERS: hwndParent - window handle of calling application. This
  839. // handle will be used as the parent for any dialogs that
  840. // are required for error messages or the "installing files"
  841. // dialog.
  842. // lpszPhonebook - name of phone book to store the entry in
  843. // lpszEntryName - name of phone book entry to be
  844. // created or modified
  845. // lpRasEntry - specifies a RASENTRY struct that contains
  846. // the phone book entry data for the entry lpszEntryName
  847. // lpszUsername - username to associate with the phone book entry
  848. // lpszPassword - password to associate with the phone book entry
  849. // lpszProfileName - Name of client info profile to
  850. // retrieve. If this is NULL, the default profile is used.
  851. // lpINetClientInfo - client information
  852. // dwfOptions - a combination of INETCFG_ flags that controls
  853. // the installation and configuration as follows:
  854. //
  855. // INETCFG_INSTALLMAIL - install exchange and internet mail
  856. // INETCFG_INSTALLMODEM - Invoke InstallModem wizard if NO
  857. // MODEM IS INSTALLED. Note that if
  858. // no modem is installed and this flag
  859. // is not set, the function will fail
  860. // INETCFG_INSTALLRNA - install RNA (if needed)
  861. // INETCFG_INSTALLTCP - install TCP/IP (if needed)
  862. // INETCFG_CONNECTOVERLAN - connecting with LAN (vs modem)
  863. // INETCFG_SETASAUTODIAL - Set the phone book entry for autodial
  864. // INETCFG_OVERWRITEENTRY - Overwrite the phone book entry if it
  865. // exists. Note: if this flag is not
  866. // set, and the entry exists, a unique
  867. // name will be created for the entry.
  868. // INETCFG_WARNIFSHARINGBOUND - Check if TCP/IP file sharing is
  869. // turned on, and warn user to turn
  870. // it off. Reboot is required if
  871. // the user turns it off.
  872. // INETCFG_REMOVEIFSHARINGBOUND - Check if TCP/IP file sharing is
  873. // turned on, and force user to turn
  874. // it off. If user does not want to
  875. // turn it off, return will be
  876. // ERROR_CANCELLED. Reboot is
  877. // required if the user turns it off.
  878. //
  879. // lpfNeedsRestart - if non-NULL, then on return, this will be
  880. // TRUE if windows must be restarted to complete the installation.
  881. //
  882. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  883. //
  884. // HISTORY:
  885. // 96/03/11 markdu Created.
  886. //
  887. //*******************************************************************
  888. #ifdef UNICODE
  889. extern "C" HRESULT WINAPI InetConfigClientA
  890. (
  891. HWND hwndParent,
  892. LPCSTR lpszPhonebook,
  893. LPCSTR lpszEntryName,
  894. LPRASENTRY lpRasEntry,
  895. LPCSTR lpszUsername,
  896. LPCSTR lpszPassword,
  897. LPCSTR lpszProfileName,
  898. LPINETCLIENTINFOA lpINetClientInfo,
  899. DWORD dwfOptions,
  900. LPBOOL lpfNeedsRestart
  901. )
  902. {
  903. LPTSTR pszPhonebook = NULL;
  904. LPTSTR pszEntryName = NULL;
  905. LPTSTR pszUsername = NULL;
  906. LPTSTR pszPassword = NULL;
  907. LPTSTR pszProfileName = NULL;
  908. INETCLIENTINFOW *pINetClientInfo = NULL;
  909. TCHAR szPhonebook[sizeof(TCHAR*)*(MAX_PATH+1)] = TEXT("");
  910. TCHAR szEntryName[sizeof(TCHAR*)*(MAX_PATH+1)] = TEXT("");
  911. TCHAR szUsername[sizeof(TCHAR*)*(MAX_PATH+1)] = TEXT("");
  912. TCHAR szPassword[sizeof(TCHAR*)*(MAX_PATH+1)] = TEXT("");
  913. TCHAR szProfileName[sizeof(TCHAR*)*(MAX_PATH+1)] = TEXT("");
  914. INETCLIENTINFOW INetClientInfo;
  915. if (NULL != lpszPhonebook)
  916. {
  917. mbstowcs(szPhonebook, lpszPhonebook, lstrlenA(lpszPhonebook)+1);
  918. pszPhonebook = szPhonebook;
  919. }
  920. if (NULL != lpszEntryName)
  921. {
  922. mbstowcs(szEntryName, lpszEntryName, lstrlenA(lpszEntryName)+1);
  923. pszEntryName = szEntryName;
  924. }
  925. if (NULL != lpszUsername)
  926. {
  927. mbstowcs(szUsername, lpszUsername, lstrlenA(lpszUsername)+1);
  928. pszUsername = szUsername;
  929. }
  930. if (NULL != lpszPassword)
  931. {
  932. mbstowcs(szPassword, lpszPassword, lstrlenA(lpszPassword)+1);
  933. pszPassword = szPassword;
  934. }
  935. if (NULL != lpszProfileName)
  936. {
  937. mbstowcs(szProfileName, lpszProfileName, lstrlenA(lpszProfileName)+1);
  938. pszProfileName = szProfileName;
  939. }
  940. if (lpINetClientInfo)
  941. {
  942. ToUnicodeClientInfo(&INetClientInfo, lpINetClientInfo);
  943. pINetClientInfo = &INetClientInfo;
  944. }
  945. return InetConfigClientW(hwndParent,
  946. pszPhonebook,
  947. pszEntryName,
  948. lpRasEntry,
  949. pszUsername,
  950. pszPassword,
  951. pszProfileName,
  952. pINetClientInfo,
  953. dwfOptions,
  954. lpfNeedsRestart);
  955. }
  956. extern "C" HRESULT WINAPI InetConfigClientW
  957. #else
  958. extern "C" HRESULT WINAPI InetConfigClientA
  959. #endif
  960. (
  961. HWND hwndParent,
  962. LPCTSTR lpszPhonebook,
  963. LPCTSTR lpszEntryName,
  964. LPRASENTRY lpRasEntry,
  965. LPCTSTR lpszUsername,
  966. LPCTSTR lpszPassword,
  967. LPCTSTR lpszProfileName,
  968. LPINETCLIENTINFO lpINetClientInfo,
  969. DWORD dwfOptions,
  970. LPBOOL lpfNeedsRestart
  971. )
  972. {
  973. TCHAR szConnectoidName[MAX_ISP_NAME + 1] = TEXT("");
  974. BOOL fNeedsRestart = FALSE; // Default to no reboot needed
  975. HWND hwndWaitDlg = NULL;
  976. DEBUGMSG("export.c::InetConfigClient()");
  977. // Install files if needed.
  978. // Note: the parent hwnd is validated in InetConfigSystem
  979. // We must also mask out the InstallModem flag since we want to
  980. // do that here, not in InetConfigSystem
  981. DWORD dwRet = InetConfigSystem(hwndParent,
  982. dwfOptions & ~INETCFG_INSTALLMODEM, &fNeedsRestart);
  983. if (ERROR_SUCCESS != dwRet)
  984. {
  985. return dwRet;
  986. }
  987. // 4/2/97 ChrisK Olympus 209 Display busy dialog
  988. if (INETCFG_SHOWBUSYANIMATION == (dwfOptions & INETCFG_SHOWBUSYANIMATION))
  989. hwndWaitDlg = WaitCfgInit(hwndParent,IDS_WAITCONNECT);
  990. // Make sure we have a connectoid name
  991. if (lpszEntryName && lstrlen(lpszEntryName))
  992. {
  993. // Copy the name into a private buffer in case we have
  994. // to muck around with it
  995. lstrcpyn(szConnectoidName, lpszEntryName, sizeof(szConnectoidName)/sizeof(TCHAR));
  996. // Make sure the name is valid.
  997. dwRet = ValidateConnectoidName(lpszPhonebook, szConnectoidName);
  998. if ((ERROR_SUCCESS == dwRet) ||
  999. (ERROR_ALREADY_EXISTS == dwRet))
  1000. {
  1001. // Find out if we can overwrite an existing connectoid
  1002. if (!(dwfOptions & INETCFG_OVERWRITEENTRY) &&
  1003. (ERROR_ALREADY_EXISTS == dwRet))
  1004. {
  1005. TCHAR szConnectoidNameBase[MAX_ISP_NAME + 1];
  1006. // Create a base string that is truncated to leave room for a space
  1007. // and a 3-digit number to be appended. So, the buffer size will be
  1008. // MAX_ISP_NAME + 1 - (LEN_APPEND_INT + 1)
  1009. lstrcpyn(szConnectoidNameBase, szConnectoidName,
  1010. MAX_ISP_NAME - LEN_APPEND_INT);
  1011. // If the entry exists, we have to create a unique name
  1012. int nSuffix = 2;
  1013. while ((ERROR_ALREADY_EXISTS == dwRet) && (nSuffix < MAX_APPEND_INT))
  1014. {
  1015. // Add the integer to the end of the base string and then bump it
  1016. wsprintf(szConnectoidName, szFmtAppendIntToString,
  1017. szConnectoidNameBase, nSuffix++);
  1018. // Validate this new name
  1019. dwRet = ValidateConnectoidName(lpszPhonebook, szConnectoidName);
  1020. }
  1021. // If we could not create a unique name, bail
  1022. // Note that dwRet should still be ERROR_ALREADY_EXISTS in this case
  1023. if (nSuffix >= MAX_APPEND_INT)
  1024. {
  1025. if (NULL != hwndWaitDlg)
  1026. DestroyWindow(hwndWaitDlg);
  1027. hwndWaitDlg = NULL;
  1028. return dwRet;
  1029. }
  1030. }
  1031. if (lpRasEntry && lpRasEntry->dwSize == sizeof(RASENTRY))
  1032. {
  1033. // Create a connectoid with given properties
  1034. dwRet = MakeConnectoid(hwndParent, dwfOptions, lpszPhonebook,
  1035. szConnectoidName, lpRasEntry, lpszUsername, lpszPassword, &fNeedsRestart);
  1036. }
  1037. // If we created a connectoid, we already updated the dial params
  1038. // with the user name and password. However, if we didn't create a
  1039. // connectoid we still may need to update dial params of an existing one
  1040. else if ((lpszUsername && lstrlen(lpszUsername)) ||
  1041. (lpszPassword && lstrlen(lpszPassword)))
  1042. {
  1043. // Update the dial params for the given connectoid.
  1044. dwRet = SetConnectoidUsername(lpszPhonebook, szConnectoidName,
  1045. lpszUsername, lpszPassword);
  1046. }
  1047. // If the connectoid was created/updated successfully, see
  1048. // if it is supposed to be set as the autodial connectoid.
  1049. if ((ERROR_SUCCESS == dwRet) && (dwfOptions & INETCFG_SETASAUTODIAL))
  1050. {
  1051. dwRet = InetSetAutodial((DWORD)TRUE, szConnectoidName);
  1052. // make sure "The Internet" icon on desktop points to web browser
  1053. // (it may initially be pointing at internet wizard)
  1054. // 96/04/22 markdu NASH BUG 18901 Do not do this for temp connectoids.
  1055. if (!(dwfOptions & INETCFG_TEMPPHONEBOOKENTRY))
  1056. {
  1057. // //10/24/96 jmazner Normandy 6968
  1058. // //No longer neccessary thanks to Valdon's hooks for invoking ICW.
  1059. // 11/21/96 jmazner Normandy 11812
  1060. // oops, it _is_ neccessary, since if user downgrades from IE 4 to IE 3,
  1061. // ICW 1.1 needs to morph the IE 3 icon.
  1062. SetDesktopInternetIconToBrowser();
  1063. }
  1064. }
  1065. }
  1066. }
  1067. // Now set the client info if provided and no errors have occurred yet.
  1068. if (ERROR_SUCCESS == dwRet)
  1069. {
  1070. if (NULL != lpINetClientInfo)
  1071. {
  1072. dwRet = InetSetClientInfo(lpszProfileName, lpINetClientInfo);
  1073. if (ERROR_SUCCESS != dwRet)
  1074. {
  1075. if (NULL != hwndWaitDlg)
  1076. DestroyWindow(hwndWaitDlg);
  1077. hwndWaitDlg = NULL;
  1078. return dwRet;
  1079. }
  1080. // update IE news settings
  1081. dwRet = SetIEClientInfo(lpINetClientInfo);
  1082. if (ERROR_SUCCESS != dwRet)
  1083. {
  1084. if (NULL != hwndWaitDlg)
  1085. DestroyWindow(hwndWaitDlg);
  1086. hwndWaitDlg = NULL;
  1087. return dwRet;
  1088. }
  1089. }
  1090. // Now update the mail client if we were asked to do so.
  1091. // Note: if we got here without errors, and INETCFG_INSTALLMAIL is set,
  1092. // then mail has been installed by now.
  1093. if (dwfOptions & INETCFG_INSTALLMAIL)
  1094. {
  1095. INETCLIENTINFO INetClientInfo;
  1096. ZeroMemory(&INetClientInfo, sizeof(INETCLIENTINFO));
  1097. INetClientInfo.dwSize = sizeof(INETCLIENTINFO);
  1098. // Use a temp pointer that we can modify.
  1099. LPINETCLIENTINFO lpTmpINetClientInfo = lpINetClientInfo;
  1100. // If no client info struct was given, try to get the profile by name
  1101. if ((NULL == lpTmpINetClientInfo) && (NULL != lpszProfileName) &&
  1102. lstrlen(lpszProfileName))
  1103. {
  1104. lpTmpINetClientInfo = &INetClientInfo;
  1105. dwRet = InetGetClientInfo(lpszProfileName, lpTmpINetClientInfo);
  1106. if (ERROR_SUCCESS != dwRet)
  1107. {
  1108. if (NULL != hwndWaitDlg)
  1109. DestroyWindow(hwndWaitDlg);
  1110. hwndWaitDlg = NULL;
  1111. return dwRet;
  1112. }
  1113. }
  1114. // If we still don't have client info, we should enumerate the profiles
  1115. // If there is one profile, get it. If multiple, show UI to allow user
  1116. // to choose. If none, there is nothing to do at this point.
  1117. // For now, we don't support enumeration, so just try to get the default.
  1118. if (NULL == lpTmpINetClientInfo)
  1119. {
  1120. lpTmpINetClientInfo = &INetClientInfo;
  1121. dwRet = InetGetClientInfo(NULL, lpTmpINetClientInfo);
  1122. if (ERROR_SUCCESS != dwRet)
  1123. {
  1124. if (NULL != hwndWaitDlg)
  1125. DestroyWindow(hwndWaitDlg);
  1126. hwndWaitDlg = NULL;
  1127. return dwRet;
  1128. }
  1129. }
  1130. // If we have client info, update mail settings.
  1131. if (NULL != lpTmpINetClientInfo)
  1132. {
  1133. dwRet = UpdateMailSettings(hwndParent, lpTmpINetClientInfo,
  1134. szConnectoidName);
  1135. }
  1136. }
  1137. }
  1138. // tell caller whether we need to reboot or not
  1139. if ((ERROR_SUCCESS == dwRet) && (lpfNeedsRestart))
  1140. {
  1141. *lpfNeedsRestart = fNeedsRestart;
  1142. }
  1143. if (NULL != hwndWaitDlg)
  1144. DestroyWindow(hwndWaitDlg);
  1145. hwndWaitDlg = NULL;
  1146. return dwRet;
  1147. }
  1148. //*******************************************************************
  1149. //
  1150. // FUNCTION: UpdateMailSettings
  1151. //
  1152. // PURPOSE: This function will update the settings for mail in
  1153. // the profile of the user's choice.
  1154. //
  1155. // PARAMETERS: hwndParent - window handle of calling application. This
  1156. // handle will be used as the parent for any dialogs that
  1157. // are required for error messages or the "choose profile"
  1158. // dialog.
  1159. // lpINetClientInfo - client information
  1160. // lpszEntryName - name of phone book entry to be
  1161. // set for connection.
  1162. //
  1163. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1164. //
  1165. // HISTORY:
  1166. // 96/03/26 markdu Created.
  1167. //
  1168. //*******************************************************************
  1169. HRESULT UpdateMailSettings(
  1170. HWND hwndParent,
  1171. LPINETCLIENTINFO lpINetClientInfo,
  1172. LPTSTR lpszEntryName)
  1173. {
  1174. DWORD dwRet = ERROR_SUCCESS;
  1175. MAILCONFIGINFO MailConfigInfo;
  1176. ZeroMemory(&MailConfigInfo,sizeof(MAILCONFIGINFO)); // zero out structure
  1177. if (NULL == gpWizardState)
  1178. {
  1179. gpWizardState = new WIZARDSTATE;
  1180. ASSERT(gpWizardState);
  1181. if (gpWizardState)
  1182. {
  1183. InitWizardState(gpWizardState, 0);
  1184. }
  1185. else
  1186. {
  1187. return ERROR_OUTOFMEMORY;
  1188. }
  1189. }
  1190. // call MAPI to set up profile and store this information in it
  1191. if (InitMAPI(hwndParent))
  1192. {
  1193. CHOOSEPROFILEDLGINFO ChooseProfileDlgInfo;
  1194. ZeroMemory(&ChooseProfileDlgInfo, sizeof(CHOOSEPROFILEDLGINFO));
  1195. ChooseProfileDlgInfo.fSetProfileAsDefault = TRUE;
  1196. ENUM_MAPI_PROFILE* pEnumMapiProfile = new(ENUM_MAPI_PROFILE);
  1197. if (pEnumMapiProfile && pEnumMapiProfile->GetEntryCount())
  1198. {
  1199. // Display a dialog and allow the user to select/create profile
  1200. BOOL fRet=(BOOL)DialogBoxParam(ghInstance,MAKEINTRESOURCE(IDD_CHOOSEPROFILENAME),
  1201. hwndParent, ChooseProfileDlgProc,(LPARAM) &ChooseProfileDlgInfo);
  1202. if (FALSE == fRet)
  1203. {
  1204. // user cancelled, bail
  1205. return ERROR_CANCELLED;
  1206. }
  1207. }
  1208. if (pEnumMapiProfile)
  1209. {
  1210. delete(pEnumMapiProfile);
  1211. pEnumMapiProfile = NULL;
  1212. }
  1213. // set up a structure with mail config information
  1214. MailConfigInfo.pszEmailAddress = lpINetClientInfo->szEMailAddress;
  1215. MailConfigInfo.pszEmailServer = lpINetClientInfo->szPOPServer;
  1216. MailConfigInfo.pszEmailDisplayName = lpINetClientInfo->szEMailName;
  1217. MailConfigInfo.pszEmailAccountName = lpINetClientInfo->szPOPLogonName;
  1218. MailConfigInfo.pszEmailAccountPwd = lpINetClientInfo->szPOPLogonPassword;
  1219. MailConfigInfo.pszConnectoidName = lpszEntryName;
  1220. MailConfigInfo.fRememberPassword = TRUE;
  1221. MailConfigInfo.pszProfileName = ChooseProfileDlgInfo.szProfileName;
  1222. MailConfigInfo.fSetProfileAsDefault = ChooseProfileDlgInfo.fSetProfileAsDefault;
  1223. // BUGBUG SMTP
  1224. // set up the profile through MAPI
  1225. dwRet = SetMailProfileInformation(&MailConfigInfo);
  1226. if (ERROR_SUCCESS != dwRet)
  1227. {
  1228. DisplayErrorMessage(hwndParent,IDS_ERRConfigureMail,
  1229. (DWORD) dwRet,ERRCLS_MAPI,MB_ICONEXCLAMATION);
  1230. }
  1231. DeInitMAPI();
  1232. }
  1233. else
  1234. {
  1235. // an error occurred.
  1236. dwRet = GetLastError();
  1237. if (ERROR_SUCCESS == dwRet)
  1238. {
  1239. // Error occurred, but the error code was not set.
  1240. dwRet = ERROR_INETCFG_UNKNOWN;
  1241. }
  1242. }
  1243. return dwRet;
  1244. }
  1245. //*******************************************************************
  1246. //
  1247. // FUNCTION: MakeConnectoid
  1248. //
  1249. // PURPOSE: This function will create a connectoid with the
  1250. // supplied name if lpRasEntry points to a valid RASENTRY
  1251. // struct. If username and password are given, these
  1252. // will be set as the dial params for the connectoid.
  1253. //
  1254. // PARAMETERS:
  1255. // hwndParent - window handle of calling application. This
  1256. // handle will be used as the parent for any dialogs that
  1257. // are required for error messages or the "choose modem"
  1258. // dialog.
  1259. // dwfOptions - a combination of INETCFG_ flags that controls
  1260. // the installation and configuration.
  1261. // lpszPhonebook - name of phone book to store the entry in
  1262. // lpszEntryName - name of connectoid to create/modify
  1263. // lpRasEntry - connectoid data
  1264. // lpszUsername - username to associate with connectoid
  1265. // lpszPassword - password to associate with connectoid
  1266. // lpfNeedsRestart - set to true if we need a restart. Note that
  1267. // since this is an internal helper function, we
  1268. // assume that the pointer is valid, and we don't
  1269. // initialize it (we only touch it if we are setting
  1270. // it to TRUE).
  1271. //
  1272. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1273. //
  1274. // HISTORY:
  1275. // 96/03/12 markdu Created.
  1276. //
  1277. //*******************************************************************
  1278. DWORD MakeConnectoid(
  1279. HWND hwndParent,
  1280. DWORD dwfOptions,
  1281. LPCTSTR lpszPhonebook,
  1282. LPCTSTR lpszEntryName,
  1283. LPRASENTRY lpRasEntry,
  1284. LPCTSTR lpszUsername,
  1285. LPCTSTR lpszPassword,
  1286. LPBOOL lpfNeedsRestart)
  1287. {
  1288. DWORD dwRet;
  1289. ASSERT(lpfNeedsRestart);
  1290. if (dwfOptions & RASEO_UseCountryAndAreaCodes)
  1291. {
  1292. if ((0 == lpRasEntry->dwCountryCode) || (0 == lpRasEntry->dwCountryID))
  1293. return ERROR_INVALID_PARAMETER;
  1294. }
  1295. if (0 == lstrlen(lpRasEntry->szLocalPhoneNumber))
  1296. {
  1297. return ERROR_INVALID_PARAMETER;
  1298. }
  1299. // Load RNA if not already loaded since ENUM_MODEM needs it.
  1300. dwRet = EnsureRNALoaded();
  1301. if (ERROR_SUCCESS != dwRet)
  1302. {
  1303. return dwRet;
  1304. }
  1305. //
  1306. // Enumerate the modems
  1307. //
  1308. ENUM_MODEM EnumModem;
  1309. dwRet = EnumModem.GetError();
  1310. if (ERROR_SUCCESS != dwRet)
  1311. {
  1312. return dwRet;
  1313. }
  1314. if (TRUE == IsNT())
  1315. {
  1316. BOOL bNeedModem = FALSE;
  1317. if (NULL == lpIcfgNeedModem)
  1318. return ERROR_GEN_FAILURE;
  1319. dwRet = (*lpIcfgNeedModem)(0, &bNeedModem);
  1320. if (ERROR_SUCCESS != dwRet)
  1321. {
  1322. return dwRet;
  1323. }
  1324. if (TRUE == bNeedModem)
  1325. {
  1326. if (NULL == lpIcfgInstallModem)
  1327. return ERROR_GEN_FAILURE;
  1328. dwRet = (*lpIcfgInstallModem)(NULL, 0, lpfNeedsRestart);
  1329. //
  1330. // TODO: Check to see if user cancelled
  1331. //
  1332. }
  1333. }
  1334. else
  1335. {
  1336. // If there are no modems, install one if requested.
  1337. if (0 == EnumModem.GetNumDevices())
  1338. {
  1339. if (!(dwfOptions & INETCFG_INSTALLMODEM))
  1340. {
  1341. // We have not been asked to install a modem, so there
  1342. // is nothing further we can do.
  1343. return ERROR_INVALID_PARAMETER;
  1344. }
  1345. if (FALSE == IsNT())
  1346. {
  1347. //
  1348. // 5/22/97 jmazner Olympus #4698
  1349. // On Win95, calling RasEnumDevices launches RNAAP.EXE
  1350. // If RNAAP.EXE is running, any modems you install won't be usable
  1351. // So, nuke RNAAP.EXE before installing the modem.
  1352. //
  1353. TCHAR szWindowTitle[255] = TEXT("\0nogood");
  1354. //
  1355. // Unload the RAS dll's before killing RNAAP, just to be safe
  1356. //
  1357. DeInitRNA();
  1358. LoadSz(IDS_RNAAP_TITLE,szWindowTitle,255);
  1359. HWND hwnd = FindWindow(szWindowTitle, NULL);
  1360. if (NULL != hwnd)
  1361. {
  1362. if (!PostMessage(hwnd, WM_CLOSE, 0, 0))
  1363. {
  1364. DEBUGMSG("Trying to kill RNAAP window returned getError %d", GetLastError());
  1365. }
  1366. }
  1367. }
  1368. // invoke the modem wizard UI to install the modem
  1369. UINT uRet = InvokeModemWizard(NULL);
  1370. if (uRet != ERROR_SUCCESS)
  1371. {
  1372. DisplayErrorMessage(hwndParent,IDS_ERRInstallModem,uRet,
  1373. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  1374. return ERROR_INVALID_PARAMETER;
  1375. }
  1376. if (FALSE == IsNT())
  1377. {
  1378. // Reload the RAS dlls now that the modem has been safely installed.
  1379. InitRNA(hwndParent);
  1380. }
  1381. // Re-numerate the modems to be sure we have the most recent changes
  1382. dwRet = EnumModem.ReInit();
  1383. if (ERROR_SUCCESS != dwRet)
  1384. {
  1385. return dwRet;
  1386. }
  1387. // If there are still no modems, user cancelled
  1388. if (0 == EnumModem.GetNumDevices())
  1389. {
  1390. return ERROR_CANCELLED;
  1391. }
  1392. else
  1393. {
  1394. // ChrisK 5-2-97 Removed per GeoffR
  1395. // // 96/05/01 markdu ICW BUG 8049 Reboot if modem is installed.
  1396. // *lpfNeedsRestart = TRUE;
  1397. }
  1398. }
  1399. }
  1400. // Validate the device if possible
  1401. if (lstrlen(lpRasEntry->szDeviceName) && lstrlen(lpRasEntry->szDeviceType))
  1402. {
  1403. // Verify that there is a device with the given name and type
  1404. if (!EnumModem.VerifyDeviceNameAndType(lpRasEntry->szDeviceName,
  1405. lpRasEntry->szDeviceType))
  1406. {
  1407. // There was no device that matched both name and type,
  1408. // so reset the strings and bring up the choose modem UI.
  1409. lpRasEntry->szDeviceName[0] = '\0';
  1410. lpRasEntry->szDeviceType[0] = '\0';
  1411. }
  1412. }
  1413. else if (lstrlen(lpRasEntry->szDeviceName))
  1414. {
  1415. // Only the name was given. Try to find a matching type.
  1416. // If this fails, fall through to recovery case below.
  1417. LPTSTR szDeviceType =
  1418. EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  1419. if (szDeviceType)
  1420. {
  1421. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  1422. }
  1423. }
  1424. else if (lstrlen(lpRasEntry->szDeviceType))
  1425. {
  1426. // Only the type was given. Try to find a matching name.
  1427. // If this fails, fall through to recovery case below.
  1428. LPTSTR szDeviceName =
  1429. EnumModem.GetDeviceNameFromType(lpRasEntry->szDeviceType);
  1430. if (szDeviceName)
  1431. {
  1432. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  1433. }
  1434. }
  1435. // If either name or type is missing, bring up choose modem UI if there
  1436. // are multiple devices, else just get first device.
  1437. // Since we already verified that there was at least one device,
  1438. // we can assume that this will succeed.
  1439. if(!lstrlen(lpRasEntry->szDeviceName) ||
  1440. !lstrlen(lpRasEntry->szDeviceType))
  1441. {
  1442. if (1 == EnumModem.GetNumDevices())
  1443. {
  1444. // There is just one device installed, so copy the name
  1445. lstrcpy (lpRasEntry->szDeviceName, EnumModem.Next());
  1446. }
  1447. else
  1448. {
  1449. // structure to pass to dialog to fill out
  1450. CHOOSEMODEMDLGINFO ChooseModemDlgInfo;
  1451. // Display a dialog and allow the user to select modem
  1452. BOOL fRet=(BOOL)DialogBoxParam(ghInstance,MAKEINTRESOURCE(IDD_CHOOSEMODEMNAME),hwndParent,
  1453. ChooseModemDlgProc,(LPARAM) &ChooseModemDlgInfo);
  1454. if (FALSE == fRet)
  1455. {
  1456. // user cancelled or an error occurred.
  1457. dwRet = GetLastError();
  1458. if (ERROR_SUCCESS == dwRet)
  1459. {
  1460. // Error occurred, but the error code was not set.
  1461. dwRet = ERROR_INETCFG_UNKNOWN;
  1462. }
  1463. return dwRet;
  1464. }
  1465. // Copy the modem name string
  1466. lstrcpy (lpRasEntry->szDeviceName, ChooseModemDlgInfo.szModemName);
  1467. }
  1468. // Now get the type string for this modem
  1469. lstrcpy (lpRasEntry->szDeviceType,
  1470. EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName));
  1471. ASSERT(lstrlen(lpRasEntry->szDeviceName));
  1472. ASSERT(lstrlen(lpRasEntry->szDeviceType));
  1473. }
  1474. // Create a connectoid with given properties
  1475. dwRet = CreateConnectoid(lpszPhonebook, lpszEntryName, lpRasEntry,
  1476. lpszUsername,lpszPassword);
  1477. // 96/05/06 markdu NASH BUG 21027 If DNS is set globally, clear it out so
  1478. // the per-connectoid settings will be saved.
  1479. BOOL fTemp;
  1480. DoDNSCheck(hwndParent,&fTemp);
  1481. if (TRUE == fTemp)
  1482. {
  1483. *lpfNeedsRestart = TRUE;
  1484. }
  1485. return dwRet;
  1486. }
  1487. //*******************************************************************
  1488. //
  1489. // FUNCTION: InetGetAutodial
  1490. //
  1491. // PURPOSE: This function will get the autodial settings from the registry.
  1492. //
  1493. // PARAMETERS: lpfEnable - on return, this will be TRUE if autodial
  1494. // is enabled
  1495. // lpszEntryName - on return, this buffer will contain the
  1496. // name of the phone book entry that is set for autodial
  1497. // cbEntryNameSize - size of buffer for phone book entry name
  1498. //
  1499. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1500. //
  1501. // HISTORY:
  1502. // 96/03/11 markdu Created.
  1503. //
  1504. //*******************************************************************
  1505. #ifdef UNICODE
  1506. extern "C" HRESULT WINAPI InetGetAutodialA
  1507. (
  1508. LPBOOL lpfEnable,
  1509. LPSTR lpszEntryName,
  1510. DWORD cbEntryNameSize
  1511. )
  1512. {
  1513. HRESULT hr;
  1514. TCHAR *szEntryName = (TCHAR *)new TCHAR[cbEntryNameSize+1];
  1515. if(szEntryName == NULL)
  1516. {
  1517. lpszEntryName[0] = '\0';
  1518. return ERROR_NOT_ENOUGH_MEMORY;
  1519. }
  1520. hr = InetGetAutodialW(lpfEnable, szEntryName, (cbEntryNameSize)*sizeof(TCHAR));
  1521. if (hr == ERROR_SUCCESS)
  1522. {
  1523. wcstombs(lpszEntryName, szEntryName, cbEntryNameSize);
  1524. }
  1525. delete [] szEntryName;
  1526. return hr;
  1527. }
  1528. extern "C" HRESULT WINAPI InetGetAutodialW
  1529. #else
  1530. extern "C" HRESULT WINAPI InetGetAutodialA
  1531. #endif
  1532. (
  1533. LPBOOL lpfEnable,
  1534. LPTSTR lpszEntryName,
  1535. DWORD cbEntryNameSize
  1536. )
  1537. {
  1538. HRESULT dwRet;
  1539. DEBUGMSG("export.c::InetGetAutodial()");
  1540. ASSERT(lpfEnable);
  1541. ASSERT(lpszEntryName);
  1542. ASSERT(cbEntryNameSize);
  1543. if (!lpfEnable || !lpszEntryName || (cbEntryNameSize == 0))
  1544. {
  1545. return ERROR_BAD_ARGUMENTS;
  1546. }
  1547. HINSTANCE hInst = NULL;
  1548. FARPROC fp = NULL;
  1549. hInst = LoadLibrary(cszWininet);
  1550. if (hInst)
  1551. {
  1552. fp = GetProcAddress(hInst,cszInternetQueryOption);
  1553. if (fp)
  1554. {
  1555. CHAR szDefaultConnection[RAS_MaxEntryName+1];
  1556. DWORD cchDefaultConnection =
  1557. sizeof(szDefaultConnection) / sizeof(szDefaultConnection[0]);
  1558. // cchDefaultConnection counts the null-terminator
  1559. if (!((INTERNETQUERYOPTION)(fp))(
  1560. NULL,
  1561. INTERNET_OPTION_AUTODIAL_CONNECTION,
  1562. szDefaultConnection,
  1563. &cchDefaultConnection
  1564. ))
  1565. {
  1566. dwRet = GetLastError();
  1567. }
  1568. else if ((cchDefaultConnection * sizeof(TCHAR)) > cbEntryNameSize)
  1569. {
  1570. dwRet = ERROR_INSUFFICIENT_BUFFER;
  1571. }
  1572. else
  1573. {
  1574. dwRet = ERROR_SUCCESS;
  1575. if (cchDefaultConnection == 0)
  1576. {
  1577. lpszEntryName[0] = TEXT('\0');
  1578. }
  1579. else
  1580. {
  1581. #ifdef UNICODE
  1582. mbstowcs(lpszEntryName, szDefaultConnection, cchDefaultConnection);
  1583. #else
  1584. lstrcpyn(lpszEntryName, szDefaultConnection, cchDefaultConnection);
  1585. #endif
  1586. }
  1587. }
  1588. }
  1589. else
  1590. {
  1591. dwRet = GetLastError();
  1592. }
  1593. FreeLibrary(hInst);
  1594. hInst = NULL;
  1595. }
  1596. else
  1597. {
  1598. dwRet = GetLastError();
  1599. }
  1600. if (ERROR_SUCCESS != dwRet)
  1601. {
  1602. // Get the name of the connectoid set for autodial.
  1603. // HKCU\RemoteAccess\InternetProfile
  1604. RegEntry reName(szRegPathRNAWizard,HKEY_CURRENT_USER);
  1605. dwRet = reName.GetError();
  1606. if (ERROR_SUCCESS == dwRet)
  1607. {
  1608. reName.GetString(szRegValInternetProfile,lpszEntryName,cbEntryNameSize);
  1609. dwRet = reName.GetError();
  1610. }
  1611. if (ERROR_SUCCESS != dwRet)
  1612. {
  1613. return dwRet;
  1614. }
  1615. }
  1616. // Get setting from registry that indicates whether autodialing is enabled.
  1617. // HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  1618. RegEntry reEnable(szRegPathInternetSettings,HKEY_CURRENT_USER);
  1619. dwRet = reEnable.GetError();
  1620. if (ERROR_SUCCESS == dwRet)
  1621. {
  1622. DWORD dwVal = reEnable.GetNumber(szRegValEnableAutodial, 0);
  1623. dwRet = reEnable.GetError();
  1624. if (ERROR_SUCCESS == dwRet)
  1625. {
  1626. *lpfEnable = dwVal;
  1627. }
  1628. }
  1629. return dwRet;
  1630. }
  1631. //*******************************************************************
  1632. //
  1633. // FUNCTION: InetSetAutodial
  1634. //
  1635. // PURPOSE: This function will set the autodial settings in the registry.
  1636. //
  1637. // PARAMETERS: fEnable - If set to TRUE, autodial will be enabled.
  1638. // If set to FALSE, autodial will be disabled.
  1639. // lpszEntryName - name of the phone book entry to set
  1640. // for autodial. If this is "", the
  1641. // entry is cleared. If NULL, it is not changed.
  1642. //
  1643. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1644. //
  1645. // HISTORY:
  1646. // 96/03/11 markdu Created.
  1647. //
  1648. //*******************************************************************
  1649. #ifdef UNICODE
  1650. extern "C" HRESULT WINAPI InetSetAutodialA
  1651. (
  1652. BOOL fEnable,
  1653. LPCSTR lpszEntryName
  1654. )
  1655. {
  1656. HRESULT hr;
  1657. LPTSTR szEntryName;
  1658. szEntryName = ToUnicodeWithAlloc(lpszEntryName);
  1659. hr = InetSetAutodialW(fEnable, szEntryName);
  1660. if(szEntryName)
  1661. GlobalFree(szEntryName);
  1662. return hr;
  1663. }
  1664. extern "C" HRESULT WINAPI InetSetAutodialW
  1665. #else
  1666. extern "C" HRESULT WINAPI InetSetAutodialA
  1667. #endif
  1668. (
  1669. BOOL fEnable,
  1670. LPCTSTR lpszEntryName
  1671. )
  1672. {
  1673. HRESULT dwRet = ERROR_SUCCESS;
  1674. BOOL bRet = FALSE;
  1675. DEBUGMSG("export.c::InetSetAutodial()");
  1676. // 2 seperate calls:
  1677. HINSTANCE hInst = NULL;
  1678. FARPROC fp = NULL;
  1679. dwRet = ERROR_SUCCESS;
  1680. hInst = LoadLibrary(cszWininet);
  1681. if (hInst && lpszEntryName)
  1682. {
  1683. fp = GetProcAddress(hInst,cszInternetSetOption);
  1684. if (fp)
  1685. {
  1686. CHAR szNewDefaultConnection[RAS_MaxEntryName+1];
  1687. #ifdef UNICODE
  1688. wcstombs(szNewDefaultConnection, lpszEntryName, RAS_MaxEntryName);
  1689. #else
  1690. lstrcpyn(szNewDefaultConnection, lpszEntryName, lstrlen(lpszEntryName)+1);
  1691. #endif
  1692. bRet = ((INTERNETSETOPTION)fp) (NULL,
  1693. INTERNET_OPTION_AUTODIAL_CONNECTION,
  1694. szNewDefaultConnection,
  1695. strlen(szNewDefaultConnection));
  1696. if (bRet)
  1697. {
  1698. DWORD dwMode = AUTODIAL_MODE_ALWAYS;
  1699. bRet = ((INTERNETSETOPTION)fp) (NULL, INTERNET_OPTION_AUTODIAL_MODE, &dwMode, sizeof(DWORD));
  1700. }
  1701. if( !bRet )
  1702. {
  1703. dwRet = GetLastError();
  1704. DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  1705. }
  1706. }
  1707. else
  1708. {
  1709. dwRet = GetLastError();
  1710. }
  1711. }
  1712. // From DarrnMi, INTERNETSETOPTION for autodial is new for 5.5.
  1713. // We should try it this way and if the InternetSetOption fails (you'll get invalid option),
  1714. // set the registry the old way. That'll work everywhere.
  1715. if (!bRet)
  1716. {
  1717. // Set the name if given, else do not change the entry.
  1718. if (lpszEntryName)
  1719. {
  1720. // Set the name of the connectoid for autodial.
  1721. // HKCU\RemoteAccess\InternetProfile
  1722. RegEntry reName(szRegPathRNAWizard,HKEY_CURRENT_USER);
  1723. dwRet = reName.GetError();
  1724. if (ERROR_SUCCESS == dwRet)
  1725. {
  1726. dwRet = reName.SetValue(szRegValInternetProfile,lpszEntryName);
  1727. }
  1728. }
  1729. //
  1730. // 9/9/97 jmazner IE bug #57426
  1731. // IE 4 uses HKEY_CURRENT_CONFIG to store autodial settings based on current
  1732. // hardware config. We need to update this key as well as HK_CU
  1733. //
  1734. if (ERROR_SUCCESS == dwRet)
  1735. {
  1736. // Set setting in the registry that indicates whether autodialing is enabled.
  1737. // HKCC\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  1738. RegEntry reEnable(szRegPathInternetSettings,HKEY_CURRENT_CONFIG);
  1739. dwRet = reEnable.GetError();
  1740. if (ERROR_SUCCESS == dwRet)
  1741. {
  1742. dwRet = reEnable.SetValue(szRegValEnableAutodial, fEnable);
  1743. }
  1744. }
  1745. if (ERROR_SUCCESS == dwRet)
  1746. {
  1747. // Set setting in the registry that indicates whether autodialing is enabled.
  1748. // HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  1749. RegEntry reEnable(szRegPathInternetSettings,HKEY_CURRENT_USER);
  1750. dwRet = reEnable.GetError();
  1751. if (ERROR_SUCCESS == dwRet)
  1752. {
  1753. dwRet = reEnable.SetValue(szRegValEnableAutodial, fEnable);
  1754. dwRet = reEnable.SetValue(szRegValNoNetAutodial, (unsigned long)FALSE);
  1755. }
  1756. }
  1757. // 2/10/97 jmazner Normandy #9705, 13233
  1758. // Notify wininet when we change proxy or autodial
  1759. if (fp)
  1760. {
  1761. if( !((INTERNETSETOPTION)fp) (NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0) )
  1762. {
  1763. dwRet = GetLastError();
  1764. DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  1765. }
  1766. }
  1767. else
  1768. {
  1769. dwRet = GetLastError();
  1770. }
  1771. }
  1772. if (hInst)
  1773. {
  1774. FreeLibrary(hInst);
  1775. hInst = NULL;
  1776. }
  1777. return dwRet;
  1778. }
  1779. /*******************************************************************
  1780. NAME: NeedDriversDlgProc
  1781. SYNOPSIS: Dialog proc for installing drivers
  1782. ********************************************************************/
  1783. UINT g_uQueryCancelAutoPlay = 0;
  1784. INT_PTR CALLBACK NeedDriversDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  1785. {
  1786. switch (uMsg)
  1787. {
  1788. case WM_INITDIALOG:
  1789. {
  1790. // lParam contains pointer to NEEDDRIVERSDLGINFO struct, set it
  1791. // in window data
  1792. ASSERT(lParam);
  1793. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  1794. return NeedDriversDlgInit(hDlg,(PNEEDDRIVERSDLGINFO) lParam);
  1795. break;
  1796. }
  1797. case WM_COMMAND:
  1798. {
  1799. switch (LOWORD(wParam))
  1800. {
  1801. case IDOK:
  1802. {
  1803. // get data pointer from window data
  1804. PNEEDDRIVERSDLGINFO pNeedDriversDlgInfo =
  1805. (PNEEDDRIVERSDLGINFO) GetWindowLongPtr(hDlg,DWLP_USER);
  1806. ASSERT(pNeedDriversDlgInfo);
  1807. // pass the data to the OK handler
  1808. int fRet=NeedDriversDlgOK(hDlg,pNeedDriversDlgInfo);
  1809. EndDialog(hDlg,fRet);
  1810. break;
  1811. }
  1812. case IDCANCEL:
  1813. {
  1814. SetLastError(ERROR_CANCELLED);
  1815. EndDialog(hDlg,0);
  1816. break;
  1817. }
  1818. }
  1819. break;
  1820. }
  1821. default:
  1822. {
  1823. if(!g_uQueryCancelAutoPlay)
  1824. g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
  1825. if (uMsg && uMsg == g_uQueryCancelAutoPlay)
  1826. return 1;
  1827. }
  1828. }
  1829. return FALSE;
  1830. }
  1831. /*******************************************************************
  1832. NAME: NeedDriversDlgInit
  1833. SYNOPSIS: proc to handle initialization of dialog for installing files
  1834. ********************************************************************/
  1835. BOOL NeedDriversDlgInit(HWND hDlg,PNEEDDRIVERSDLGINFO pNeedDriversDlgInfo)
  1836. {
  1837. ASSERT(pNeedDriversDlgInfo);
  1838. // put the dialog in the center of the screen
  1839. RECT rc;
  1840. GetWindowRect(hDlg, &rc);
  1841. SetWindowPos(hDlg, NULL,
  1842. ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  1843. ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  1844. 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  1845. return TRUE;
  1846. }
  1847. /*******************************************************************
  1848. NAME: NeedDriversDlgOK
  1849. SYNOPSIS: OK handler for dialog for installing files
  1850. ********************************************************************/
  1851. int NeedDriversDlgOK(HWND hDlg,PNEEDDRIVERSDLGINFO pNeedDriversDlgInfo)
  1852. {
  1853. int nResult = 1;
  1854. ASSERT(pNeedDriversDlgInfo);
  1855. // set the dialog text to "Installing files..." to give feedback to
  1856. // user
  1857. TCHAR szMsg[MAX_RES_LEN+1];
  1858. LoadSz(IDS_INSTALLING_FILES,szMsg,sizeof(szMsg));
  1859. SetDlgItemText(hDlg,IDC_TX_STATUS,szMsg);
  1860. // disable buttons & dialog so it can't get focus
  1861. EnableDlg(hDlg, FALSE);
  1862. FARPROC hShell32VersionProc = NULL;
  1863. BOOL bWasEnabled = FALSE;
  1864. // install the drivers we need
  1865. HMODULE hShell32Mod = (HMODULE)LoadLibrary(TEXT("shell32.dll"));
  1866. if (hShell32Mod)
  1867. hShell32VersionProc = GetProcAddress(hShell32Mod, "DllGetVersion");
  1868. if(!hShell32VersionProc)
  1869. bWasEnabled = TweakAutoRun(FALSE);
  1870. DWORD dwRet = lpIcfgInstallInetComponents(hDlg,
  1871. pNeedDriversDlgInfo->dwfOptions,
  1872. pNeedDriversDlgInfo->lpfNeedsRestart);
  1873. if(!hShell32VersionProc)
  1874. TweakAutoRun(bWasEnabled);
  1875. if (ERROR_SUCCESS != dwRet)
  1876. {
  1877. //
  1878. // Don't display error message if user cancelled
  1879. //
  1880. nResult = 0;
  1881. // Enable the dialog again
  1882. EnableDlg(hDlg, TRUE);
  1883. SetLastError(dwRet);
  1884. }
  1885. else
  1886. {
  1887. // Enable the dialog again
  1888. EnableDlg(hDlg, TRUE);
  1889. }
  1890. return nResult;
  1891. }
  1892. /*******************************************************************
  1893. NAME: EnableDlg
  1894. SYNOPSIS: Enables or disables the dlg buttons and the dlg
  1895. itself (so it can't receive focus)
  1896. ********************************************************************/
  1897. VOID EnableDlg(HWND hDlg,BOOL fEnable)
  1898. {
  1899. // disable/enable ok and cancel buttons
  1900. EnableWindow(GetDlgItem(hDlg,IDOK),fEnable);
  1901. EnableWindow(GetDlgItem(hDlg,IDCANCEL),fEnable);
  1902. // disable/enable dlg
  1903. EnableWindow(hDlg,fEnable);
  1904. UpdateWindow(hDlg);
  1905. }
  1906. /*******************************************************************
  1907. NAME: ChooseModemDlgProc
  1908. SYNOPSIS: Dialog proc for choosing modem
  1909. ********************************************************************/
  1910. INT_PTR CALLBACK ChooseModemDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  1911. LPARAM lParam)
  1912. {
  1913. BOOL fRet;
  1914. switch (uMsg)
  1915. {
  1916. case WM_INITDIALOG:
  1917. // lParam contains pointer to CHOOSEMODEMDLGINFO struct, set it
  1918. // in window data
  1919. ASSERT(lParam);
  1920. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  1921. fRet = ChooseModemDlgInit(hDlg,(PCHOOSEMODEMDLGINFO) lParam);
  1922. if (!fRet)
  1923. {
  1924. // An error occured.
  1925. EndDialog(hDlg,FALSE);
  1926. }
  1927. return fRet;
  1928. break;
  1929. case WM_COMMAND:
  1930. switch (LOWORD(wParam))
  1931. {
  1932. case IDOK:
  1933. {
  1934. // get data pointer from window data
  1935. PCHOOSEMODEMDLGINFO pChooseModemDlgInfo =
  1936. (PCHOOSEMODEMDLGINFO) GetWindowLongPtr(hDlg,DWLP_USER);
  1937. ASSERT(pChooseModemDlgInfo);
  1938. // pass the data to the OK handler
  1939. fRet=ChooseModemDlgOK(hDlg,pChooseModemDlgInfo);
  1940. if (fRet)
  1941. {
  1942. EndDialog(hDlg,TRUE);
  1943. }
  1944. }
  1945. break;
  1946. case IDCANCEL:
  1947. SetLastError(ERROR_CANCELLED);
  1948. EndDialog(hDlg,FALSE);
  1949. break;
  1950. }
  1951. break;
  1952. }
  1953. return FALSE;
  1954. }
  1955. /*******************************************************************
  1956. NAME: ChooseModemDlgInit
  1957. SYNOPSIS: proc to handle initialization of dialog for choosing modem
  1958. ********************************************************************/
  1959. BOOL ChooseModemDlgInit(HWND hDlg,PCHOOSEMODEMDLGINFO pChooseModemDlgInfo)
  1960. {
  1961. ASSERT(pChooseModemDlgInfo);
  1962. // put the dialog in the center of the screen
  1963. RECT rc;
  1964. GetWindowRect(hDlg, &rc);
  1965. SetWindowPos(hDlg, NULL,
  1966. ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  1967. ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  1968. 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  1969. // fill the combobox with available modems
  1970. DWORD dwRet = InitModemList(GetDlgItem(hDlg,IDC_MODEM));
  1971. if (ERROR_SUCCESS != dwRet)
  1972. {
  1973. DisplayErrorMessage(hDlg,IDS_ERREnumModem,dwRet,
  1974. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  1975. SetLastError(dwRet);
  1976. return FALSE;
  1977. }
  1978. return TRUE;
  1979. }
  1980. /*******************************************************************
  1981. NAME: ChooseModemDlgOK
  1982. SYNOPSIS: OK handler for dialog for choosing modem
  1983. ********************************************************************/
  1984. BOOL ChooseModemDlgOK(HWND hDlg,PCHOOSEMODEMDLGINFO pChooseModemDlgInfo)
  1985. {
  1986. ASSERT(pChooseModemDlgInfo);
  1987. // should always have a selection in combo box if we get here
  1988. ASSERT(ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_MODEM)) >= 0);
  1989. // get modem name out of combo box
  1990. ComboBox_GetText(GetDlgItem(hDlg,IDC_MODEM),
  1991. pChooseModemDlgInfo->szModemName,
  1992. ARRAYSIZE(pChooseModemDlgInfo->szModemName));
  1993. NULL_TERM_TCHARS(pChooseModemDlgInfo->szModemName);
  1994. ASSERT(lstrlen(pChooseModemDlgInfo->szModemName));
  1995. // clear the modem list
  1996. ComboBox_ResetContent(GetDlgItem(hDlg,IDC_MODEM));
  1997. return TRUE;
  1998. }
  1999. /*******************************************************************
  2000. NAME: ChooseProfileDlgProc
  2001. SYNOPSIS: Dialog proc for choosing profile
  2002. ********************************************************************/
  2003. INT_PTR CALLBACK ChooseProfileDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  2004. LPARAM lParam)
  2005. {
  2006. switch (uMsg)
  2007. {
  2008. case WM_INITDIALOG:
  2009. // lParam contains pointer to CHOOSEPROFILEDLGINFO struct, set it
  2010. // in window data
  2011. ASSERT(lParam);
  2012. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  2013. return ChooseProfileDlgInit(hDlg,(PCHOOSEPROFILEDLGINFO) lParam);
  2014. break;
  2015. case WM_COMMAND:
  2016. switch (LOWORD(wParam))
  2017. {
  2018. case IDOK:
  2019. {
  2020. // get data pointer from window data
  2021. PCHOOSEPROFILEDLGINFO pChooseProfileDlgInfo =
  2022. (PCHOOSEPROFILEDLGINFO) GetWindowLongPtr(hDlg,DWLP_USER);
  2023. ASSERT(pChooseProfileDlgInfo);
  2024. // pass the data to the OK handler
  2025. BOOL fRet=ChooseProfileDlgOK(hDlg,pChooseProfileDlgInfo);
  2026. if (fRet)
  2027. {
  2028. EndDialog(hDlg,TRUE);
  2029. }
  2030. }
  2031. break;
  2032. case IDCANCEL:
  2033. EndDialog(hDlg,FALSE);
  2034. break;
  2035. case IDC_NEW_PROFILE:
  2036. // user has requested to create a new profile
  2037. DoNewProfileDlg(hDlg);
  2038. return TRUE;
  2039. break;
  2040. }
  2041. break;
  2042. }
  2043. return FALSE;
  2044. }
  2045. /*******************************************************************
  2046. NAME: ChooseProfileDlgInit
  2047. SYNOPSIS: proc to handle initialization of dialog for choosing profile
  2048. ********************************************************************/
  2049. BOOL ChooseProfileDlgInit(HWND hDlg,PCHOOSEPROFILEDLGINFO pChooseProfileDlgInfo)
  2050. {
  2051. ASSERT(pChooseProfileDlgInfo);
  2052. // put the dialog in the center of the screen
  2053. // 96/04/23 markdu NASH BUG 18719 Make the choose profile dialog TOPMOST.
  2054. RECT rc;
  2055. GetWindowRect(hDlg, &rc);
  2056. SetWindowPos(hDlg, HWND_TOPMOST,
  2057. ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  2058. ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  2059. 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  2060. // populate the combo box with names of profiles
  2061. ENUM_MAPI_PROFILE EnumMapiProfile;
  2062. LPTSTR pProfileName=NULL;
  2063. BOOL fDefault;
  2064. int iSel;
  2065. HWND hwndCombo = GetDlgItem(hDlg,IDC_PROFILE_LIST);
  2066. ASSERT(hwndCombo);
  2067. // enumerate profile names
  2068. while (EnumMapiProfile.Next(&pProfileName,&fDefault))
  2069. {
  2070. ASSERT(pProfileName);
  2071. // add profile names to combo box
  2072. iSel=ComboBox_AddString(hwndCombo,pProfileName);
  2073. ASSERT(iSel >= 0);
  2074. // if this is the default profile, set it as selection
  2075. if (fDefault)
  2076. {
  2077. ComboBox_SetCurSel(hwndCombo,iSel);
  2078. }
  2079. }
  2080. // should always be a default profile (and should always be at least
  2081. // one existing profile if we get here)... but just in case, select
  2082. // the first profile in list if there's no selection made so far
  2083. if (ComboBox_GetCurSel(hwndCombo) < 0)
  2084. ComboBox_SetCurSel(hwndCombo,0);
  2085. // initialize "set this profile as default" checkbox to be the
  2086. // value that was passed in (in the structure)
  2087. CheckDlgButton(hDlg,IDC_SETDEFAULT,pChooseProfileDlgInfo->fSetProfileAsDefault);
  2088. return TRUE;
  2089. }
  2090. /*******************************************************************
  2091. NAME: ChooseProfileDlgOK
  2092. SYNOPSIS: OK handler for dialog for choosing profile
  2093. ********************************************************************/
  2094. BOOL ChooseProfileDlgOK(HWND hDlg,PCHOOSEPROFILEDLGINFO pChooseProfileDlgInfo)
  2095. {
  2096. ASSERT(pChooseProfileDlgInfo);
  2097. // should always have a selection in combo box if we get here
  2098. ASSERT(ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_PROFILE_LIST)) >= 0);
  2099. // get selected profile from combo box
  2100. ComboBox_GetText(GetDlgItem(hDlg,IDC_PROFILE_LIST),
  2101. pChooseProfileDlgInfo->szProfileName,
  2102. ARRAYSIZE(pChooseProfileDlgInfo->szProfileName));
  2103. NULL_TERM_TCHARS(pChooseProfileDlgInfo->szProfileName);
  2104. // get 'use as default profile' checkbox state
  2105. pChooseProfileDlgInfo->fSetProfileAsDefault = IsDlgButtonChecked(hDlg,
  2106. IDC_SETDEFAULT);
  2107. return TRUE;
  2108. }
  2109. //*******************************************************************
  2110. //
  2111. // FUNCTION: InetSetAutoProxy
  2112. //
  2113. // PURPOSE: This function will set the auto config proxy settings
  2114. // in the registry.
  2115. //
  2116. // PARAMETERS: fEnable - If set to TRUE, proxy will be enabled.
  2117. // If set to FALSE, proxy will be disabled.
  2118. // dwProxyDetectMode - value to be update in the
  2119. // HKEY_CURRENT_USER\Software\Microsoft
  2120. // \Windows\CurrentVersion\Internet Settings
  2121. // AutoProxyDetectMode
  2122. // lpszScriptAddr - value to be update in
  2123. // HKEY_CURRENT_USER\Software\Microsoft
  2124. // \Windows\CurrentVersion\Internet Settings
  2125. // AutoConfigURL
  2126. //
  2127. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  2128. //
  2129. //*******************************************************************
  2130. #ifdef UNICODE
  2131. HRESULT WINAPI InetSetAutoProxyA
  2132. (
  2133. BOOL fEnable,
  2134. DWORD dwProxyDetectMode,
  2135. LPCSTR lpszScriptAddr
  2136. )
  2137. {
  2138. HRESULT hr;
  2139. LPTSTR szScriptAddr;
  2140. szScriptAddr = ToUnicodeWithAlloc(lpszScriptAddr);
  2141. hr = InetSetAutoProxyW(fEnable, dwProxyDetectMode, szScriptAddr);
  2142. if(szScriptAddr)
  2143. GlobalFree(szScriptAddr);
  2144. return hr;
  2145. }
  2146. HRESULT WINAPI InetSetAutoProxyW
  2147. #else
  2148. HRESULT WINAPI InetSetAutoProxyA
  2149. #endif
  2150. (
  2151. BOOL fEnable,
  2152. DWORD dwProxyDetectMode,
  2153. LPCTSTR lpszScriptAddr
  2154. )
  2155. {
  2156. DWORD dwRet = ERROR_GEN_FAILURE;
  2157. HKEY hKey;
  2158. if (!fEnable)
  2159. return ERROR_SUCCESS;
  2160. if (ERROR_SUCCESS == (dwRet = RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_INTERNET_SETTINGS, &hKey)) )
  2161. {
  2162. RegSetValueEx(hKey,
  2163. cszRegValAutoProxyDetectMode,
  2164. 0,
  2165. REG_BINARY,
  2166. (LPBYTE) &dwProxyDetectMode,
  2167. sizeof(DWORD));
  2168. RegSetValueEx(hKey,
  2169. cszRegValAutoConfigURL,
  2170. 0,
  2171. REG_SZ,
  2172. (LPBYTE) lpszScriptAddr,
  2173. sizeof(TCHAR)*(lstrlen(lpszScriptAddr) + 1 ));
  2174. RegCloseKey(hKey);
  2175. }
  2176. return dwRet;
  2177. }
  2178. //*******************************************************************
  2179. //
  2180. // FUNCTION: InetSetProxy
  2181. //
  2182. // PURPOSE: This function will set the proxy settings in the registry.
  2183. // On Win32 platforms, it will then attempt to notify WinInet
  2184. // of the changes made.
  2185. //
  2186. // PARAMETERS: fEnable - If set to TRUE, proxy will be enabled.
  2187. // If set to FALSE, proxy will be disabled.
  2188. // lpszServer - name of the proxy server. If this is "", the
  2189. // entry is cleared. If NULL, it is not changed.
  2190. // lpszOverride - proxy override. If this is "", the
  2191. // entry is cleared. If NULL, it is not changed.
  2192. //
  2193. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  2194. //
  2195. //*******************************************************************
  2196. #ifdef UNICODE
  2197. HRESULT WINAPI InetSetProxyA
  2198. (
  2199. BOOL fEnable,
  2200. LPCSTR lpszServer,
  2201. LPCSTR lpszOverride
  2202. )
  2203. {
  2204. return ERROR_SUCCESS;
  2205. }
  2206. HRESULT WINAPI InetSetProxyW
  2207. #else
  2208. HRESULT WINAPI InetSetProxyA
  2209. #endif
  2210. (
  2211. BOOL fEnable,
  2212. LPCTSTR lpszServer,
  2213. LPCTSTR lpszOverride
  2214. )
  2215. {
  2216. return ERROR_SUCCESS;
  2217. }
  2218. //*******************************************************************
  2219. //
  2220. // FUNCTION: InetSetProxyEx
  2221. //
  2222. // PURPOSE: This function will set the proxy settings in the registry.
  2223. //
  2224. // PARAMETERS: fEnable - If set to TRUE, proxy will be enabled.
  2225. // If set to FALSE, proxy will be disabled.
  2226. // lpszConnectoidName - Name of connectoid to set proxy on
  2227. // NULL for LAN
  2228. // lpszServer - name of the proxy server. If this is "", the
  2229. // entry is cleared. If NULL, it is not changed.
  2230. // lpszOverride - proxy override. If this is "", the
  2231. // entry is cleared. If NULL, it is not changed.
  2232. //
  2233. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  2234. //
  2235. //*******************************************************************
  2236. #ifdef UNICODE
  2237. HRESULT WINAPI InetSetProxyExA
  2238. (
  2239. BOOL fEnable,
  2240. LPCSTR lpszConnectoidName,
  2241. LPCSTR lpszServer,
  2242. LPCSTR lpszOverride
  2243. )
  2244. {
  2245. TCHAR szConnectoidNameW[MAX_ISP_NAME + 1];
  2246. TCHAR szServerW[MAX_URL_STRING + 1];
  2247. TCHAR szOverrideW[MAX_URL_STRING + 1];
  2248. mbstowcs(szConnectoidNameW,lpszConnectoidName,lstrlenA(lpszConnectoidName)+1);
  2249. mbstowcs(szServerW, lpszServer, lstrlenA(lpszServer)+1);
  2250. mbstowcs(szOverrideW, lpszOverride, lstrlenA(lpszOverride)+1);
  2251. return InetSetProxyExW(fEnable, szConnectoidNameW, szServerW, szOverrideW);
  2252. }
  2253. HRESULT WINAPI InetSetProxyExW
  2254. #else
  2255. HRESULT WINAPI InetSetProxyExA
  2256. #endif
  2257. (
  2258. BOOL fEnable,
  2259. LPCTSTR lpszConnectoidName,
  2260. LPCTSTR lpszServer,
  2261. LPCTSTR lpszOverride
  2262. )
  2263. {
  2264. HKEY hKeyCU;
  2265. HKEY hKeyCC;
  2266. HKEY hKeyCULan;
  2267. DWORD dwRet = ERROR_SUCCESS;
  2268. DWORD dwSize;
  2269. DWORD dwType;
  2270. DWORD dwVal;
  2271. DEBUGMSG("export.c::InetSetProxy()");
  2272. // 12/15/98 vyung
  2273. // Change to use Wininet API to set proxy info. Old way of changing
  2274. // it through the registry is no longer supported.
  2275. HINSTANCE hInst = NULL;
  2276. FARPROC fpInternetSetOption, fpInternetQueryOption = NULL;
  2277. dwRet = ERROR_SUCCESS;
  2278. hInst = LoadLibrary(cszWininet);
  2279. if (hInst)
  2280. {
  2281. fpInternetSetOption = GetProcAddress(hInst,cszInternetSetOption);
  2282. fpInternetQueryOption = GetProcAddress(hInst,cszInternetQueryOption);
  2283. if (fpInternetSetOption)
  2284. {
  2285. INTERNET_PER_CONN_OPTION_LISTA list;
  2286. DWORD dwBufSize = sizeof(list);
  2287. CHAR szProxyServer[RAS_MaxEntryName+1];
  2288. CHAR szProxyOverride[RAS_MaxEntryName+1];
  2289. CHAR szConnectoidName[RAS_MaxEntryName+1];
  2290. DWORD dwOptions = 4; // always save FLAGS & DISCOVERY_FLAGS
  2291. BOOL fRes;
  2292. memset(szProxyServer, 0, sizeof(szProxyServer));
  2293. memset(szProxyOverride, 0, sizeof(szProxyServer));
  2294. memset(szConnectoidName, 0, sizeof(szProxyServer));
  2295. #ifdef UNICODE
  2296. if (lpszServer)
  2297. wcstombs(szProxyServer, lpszServer, RAS_MaxEntryName+1);
  2298. if(lpszOverride)
  2299. wcstombs(szProxyOverride, lpszOverride, RAS_MaxEntryName+1);
  2300. if(lpszConnectoidName)
  2301. wcstombs(szConnectoidName, lpszConnectoidName, RAS_MaxEntryName+1);
  2302. #else
  2303. if (lpszServer)
  2304. lstrcpy(szProxyServer, lpszServer);
  2305. if(lpszOverride)
  2306. lstrcpy(szProxyOverride, lpszOverride);
  2307. if(lpszConnectoidName)
  2308. lstrcpy(szConnectoidName, lpszConnectoidName);
  2309. #endif
  2310. // fill out list struct
  2311. list.dwSize = sizeof(list);
  2312. if (NULL == lpszConnectoidName)
  2313. list.pszConnection = NULL; // NULL == LAN,
  2314. else
  2315. list.pszConnection = szConnectoidName; // otherwise connectoid name
  2316. list.dwOptionCount = 1; // set three options
  2317. list.pOptions = new INTERNET_PER_CONN_OPTIONA[5];
  2318. if(NULL != list.pOptions)
  2319. {
  2320. // set flags
  2321. list.pOptions[0].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
  2322. //
  2323. // Query autodiscover flags - we just need to set one bit in there
  2324. //
  2325. if (fpInternetQueryOption)
  2326. {
  2327. if( !((INTERNETQUERYOPTION)fpInternetQueryOption) (NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize) )
  2328. {
  2329. dwRet = GetLastError();
  2330. DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  2331. }
  2332. }
  2333. else
  2334. dwRet = GetLastError();
  2335. //
  2336. // save off all other options
  2337. //
  2338. list.pOptions[0].Value.dwValue |= AUTO_PROXY_FLAG_USER_SET;
  2339. list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
  2340. list.pOptions[1].Value.dwValue = PROXY_TYPE_DIRECT;
  2341. //
  2342. // save proxy settings
  2343. //
  2344. if (fEnable)
  2345. {
  2346. list.pOptions[1].Value.dwValue |= PROXY_TYPE_PROXY;
  2347. }
  2348. list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  2349. list.pOptions[2].Value.pszValue = szProxyServer;
  2350. list.pOptions[3].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  2351. list.pOptions[3].Value.pszValue = szProxyOverride;
  2352. if (gpUserInfo)
  2353. {
  2354. //
  2355. // save autodetect
  2356. //
  2357. if (gpUserInfo->bAutoDiscovery)
  2358. {
  2359. list.pOptions[1].Value.dwValue |= PROXY_TYPE_AUTO_DETECT;
  2360. }
  2361. //
  2362. // save autoconfig
  2363. //
  2364. if (gpUserInfo->bAutoConfigScript)
  2365. {
  2366. list.pOptions[1].Value.dwValue |= PROXY_TYPE_AUTO_PROXY_URL;
  2367. list.pOptions[dwOptions].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
  2368. #ifdef UNICODE
  2369. CHAR szAutoConfigURL[MAX_URL_STRING+1];
  2370. wcstombs(szAutoConfigURL, gpUserInfo->szAutoConfigURL, MAX_URL_STRING+1);
  2371. list.pOptions[dwOptions].Value.pszValue = szAutoConfigURL;
  2372. #else
  2373. list.pOptions[dwOptions].Value.pszValue = gpUserInfo->szAutoConfigURL;
  2374. #endif
  2375. dwOptions++;
  2376. }
  2377. }
  2378. list.dwOptionCount = dwOptions;
  2379. if( !((INTERNETSETOPTION)fpInternetSetOption) (NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize) )
  2380. {
  2381. dwRet = GetLastError();
  2382. DEBUGMSG("INETCFG export.c::InetSetProxy() InternetSetOption failed");
  2383. }
  2384. delete [] list.pOptions;
  2385. }
  2386. }
  2387. else
  2388. dwRet = GetLastError();
  2389. FreeLibrary(hInst);
  2390. hInst = NULL;
  2391. }
  2392. else
  2393. {
  2394. dwRet = GetLastError();
  2395. }
  2396. return dwRet;
  2397. }
  2398. //*******************************************************************
  2399. //
  2400. // FUNCTION: InetGetProxy
  2401. //
  2402. // PURPOSE: This function will get the proxy settings from the registry.
  2403. //
  2404. // PARAMETERS: lpfEnable - on return, this will be TRUE if proxy
  2405. // is enabled
  2406. // lpszServer - on return, this buffer will contain the
  2407. // name of the proxy server
  2408. // cbServer - size of buffer for proxy server name
  2409. // lpszOverride - on return, this buffer will contain the
  2410. // name of the proxy server
  2411. // cbOverride - size of buffer for proxy override
  2412. //
  2413. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  2414. //
  2415. //*******************************************************************
  2416. #ifdef UNICODE
  2417. HRESULT WINAPI InetGetProxyA
  2418. (
  2419. LPBOOL lpfEnable,
  2420. LPSTR lpszServer,
  2421. DWORD cbServer,
  2422. LPSTR lpszOverride,
  2423. DWORD cbOverride
  2424. )
  2425. {
  2426. HRESULT hr;
  2427. TCHAR szServer[MAX_URL_STRING+1];
  2428. TCHAR szOverride[MAX_URL_STRING+1];
  2429. hr = InetGetProxyW(lpfEnable, szServer, cbServer, szOverride, cbOverride);
  2430. wcstombs(lpszServer, szServer, MAX_URL_STRING+1);
  2431. wcstombs(lpszOverride, szOverride, MAX_URL_STRING+1);
  2432. return hr;
  2433. }
  2434. HRESULT WINAPI InetGetProxyW
  2435. #else
  2436. HRESULT WINAPI InetGetProxyA
  2437. #endif
  2438. (
  2439. LPBOOL lpfEnable,
  2440. LPTSTR lpszServer,
  2441. DWORD cbServer,
  2442. LPTSTR lpszOverride,
  2443. DWORD cbOverride
  2444. )
  2445. {
  2446. HKEY hKey;
  2447. DWORD dwRet;
  2448. DWORD dwSize;
  2449. DWORD dwType;
  2450. DWORD dwVal;
  2451. DEBUGMSG("export.c::InetGetProxy()");
  2452. // NEW WININET API
  2453. //
  2454. // Read proxy and autoconfig settings for this connection
  2455. //
  2456. // Comment for UNICODE
  2457. // Wininet.dll doesn't support INTERNET_OPTION_PER_CONNECTION_OPTION
  2458. // in InternetQueryOptionW. Only InternetQueryOptionA supports the flag.
  2459. // Because of restriction of Wininet.dll I have to use A version.
  2460. // WTSEO : 3/19/99
  2461. INTERNET_PER_CONN_OPTION_LISTA list;
  2462. DWORD dwBufSize = sizeof(list);
  2463. //CHAR szEntryA[RAS_MaxEntryName + 1];
  2464. list.pszConnection = NULL;
  2465. list.dwSize = sizeof(list);
  2466. list.dwOptionCount = 4;
  2467. list.pOptions = new INTERNET_PER_CONN_OPTIONA[4];
  2468. if(NULL == list.pOptions)
  2469. {
  2470. return FALSE;
  2471. }
  2472. list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  2473. list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  2474. list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  2475. list.pOptions[3].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
  2476. HINSTANCE hInst = NULL;
  2477. FARPROC fp = NULL;
  2478. dwRet = ERROR_SUCCESS;
  2479. hInst = LoadLibrary(cszWininet);
  2480. if (hInst)
  2481. {
  2482. fp = GetProcAddress(hInst,cszInternetQueryOption);
  2483. if (fp)
  2484. {
  2485. if( !((INTERNETQUERYOPTION)fp) (NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize) )
  2486. {
  2487. dwRet = 0;//GetLastError();
  2488. DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  2489. }
  2490. }
  2491. else
  2492. dwRet = GetLastError();
  2493. FreeLibrary(hInst);
  2494. hInst = NULL;
  2495. }
  2496. else
  2497. {
  2498. dwRet = GetLastError();
  2499. }
  2500. //
  2501. // move options to gpUserInfo struct
  2502. //
  2503. if (gpUserInfo)
  2504. {
  2505. gpUserInfo->fProxyEnable = (list.pOptions[0].Value.dwValue & PROXY_TYPE_PROXY);
  2506. }
  2507. if(list.pOptions[1].Value.pszValue)
  2508. {
  2509. #ifdef UNICODE
  2510. mbstowcs(lpszServer, list.pOptions[1].Value.pszValue, MAX_URL_STRING);
  2511. #else
  2512. lstrcpyn(lpszServer, list.pOptions[1].Value.pszValue, MAX_URL_STRING);
  2513. #endif
  2514. cbServer = lstrlen(lpszServer);
  2515. }
  2516. if(list.pOptions[2].Value.pszValue)
  2517. {
  2518. #ifdef UNICODE
  2519. mbstowcs(lpszOverride, list.pOptions[2].Value.pszValue, MAX_URL_STRING);
  2520. #else
  2521. lstrcpyn(lpszOverride, list.pOptions[2].Value.pszValue, MAX_URL_STRING);
  2522. #endif
  2523. cbOverride = lstrlen(lpszOverride);;
  2524. }
  2525. //
  2526. // fill in autoconfig and autoproxy field
  2527. //
  2528. if (gpUserInfo)
  2529. {
  2530. // autoconfig enable and url
  2531. gpUserInfo->bAutoConfigScript = list.pOptions[0].Value.dwValue & PROXY_TYPE_AUTO_PROXY_URL;
  2532. if(list.pOptions[3].Value.pszValue)
  2533. {
  2534. #ifdef UNICODE
  2535. mbstowcs(gpUserInfo->szAutoConfigURL, list.pOptions[3].Value.pszValue,
  2536. lstrlenA(list.pOptions[3].Value.pszValue)+1);
  2537. #else
  2538. lstrcpy(gpUserInfo->szAutoConfigURL, list.pOptions[3].Value.pszValue);
  2539. #endif
  2540. }
  2541. // autodiscovery enable
  2542. gpUserInfo->bAutoDiscovery = list.pOptions[0].Value.dwValue & PROXY_TYPE_AUTO_DETECT;
  2543. }
  2544. // all done with options list
  2545. delete [] list.pOptions;
  2546. return dwRet;
  2547. }
  2548. //+----------------------------------------------------------------------------
  2549. // Function InetStartServices
  2550. //
  2551. // Synopsis This function guarentees that RAS services are running
  2552. //
  2553. // Arguments none
  2554. //
  2555. // Return ERROR_SUCCESS - if the services are enabled and running
  2556. //
  2557. // History 10/16/96 ChrisK Created
  2558. //-----------------------------------------------------------------------------
  2559. extern "C" HRESULT WINAPI InetStartServices()
  2560. {
  2561. ASSERT(lpIcfgStartServices);
  2562. if (NULL == lpIcfgStartServices)
  2563. return ERROR_GEN_FAILURE;
  2564. return (lpIcfgStartServices());
  2565. }
  2566. //+----------------------------------------------------------------------------
  2567. //
  2568. // Function: IEInstalled
  2569. //
  2570. // Synopsis: Tests whether a version of Internet Explorer is installed via registry keys
  2571. //
  2572. // Arguments: None
  2573. //
  2574. // Returns: TRUE - Found the IE executable
  2575. // FALSE - No IE executable found
  2576. //
  2577. // History: jmazner Created 8/19/96 (as fix for Normandy #4571)
  2578. // valdonb 10/22/96 Shamelessly stole and used for my own purposes.
  2579. //
  2580. //-----------------------------------------------------------------------------
  2581. BOOL IEInstalled(void)
  2582. {
  2583. HRESULT hr;
  2584. HKEY hKey = 0;
  2585. HANDLE hFindResult;
  2586. TCHAR szTempPath[MAX_PATH + 1] = TEXT("");
  2587. TCHAR szIELocalPath[MAX_PATH + 1] = TEXT("");
  2588. DWORD dwPathSize;
  2589. WIN32_FIND_DATA foundData;
  2590. hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegPathIexploreAppPath, 0, KEY_READ, &hKey);
  2591. if (hr != ERROR_SUCCESS) return( FALSE );
  2592. dwPathSize = sizeof (szIELocalPath);
  2593. hr = RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE) szIELocalPath, &dwPathSize);
  2594. RegCloseKey( hKey );
  2595. if (hr != ERROR_SUCCESS) return( FALSE );
  2596. //
  2597. // Olympus 9214 ChrisK
  2598. // NT5 stores the path of IExplorer with environment strings
  2599. //
  2600. if (0 == ExpandEnvironmentStrings(szIELocalPath,szTempPath,MAX_PATH))
  2601. {
  2602. return (FALSE);
  2603. };
  2604. hFindResult = FindFirstFile( szTempPath, &foundData );
  2605. FindClose( hFindResult );
  2606. if (INVALID_HANDLE_VALUE == hFindResult) return( FALSE );
  2607. return(TRUE);
  2608. }
  2609. //+----------------------------------------------------------------------------
  2610. //
  2611. // Function: IsIEAKSignUpNeeded
  2612. //
  2613. // Synopsis: Determine if the IEAK signup should be run by checking the
  2614. // IEAK's registry flag and signup file location
  2615. //
  2616. // Arguments: pszPath - buffer to contain path to signup file
  2617. // dwPathLen - size of pszPath
  2618. //
  2619. // Returns: TRUE - if IEAK signup should be run
  2620. // FALSE - IEAK signup should not be run
  2621. //
  2622. // History: ChrisK 6/18/97 Created
  2623. //
  2624. //-----------------------------------------------------------------------------
  2625. BOOL IsIEAKSignUpNeeded(LPTSTR pszPath, DWORD dwPathLen)
  2626. {
  2627. BOOL bRC = FALSE;
  2628. //
  2629. // Validate parameters
  2630. //
  2631. DEBUGMSG("INETCFG: IsIEAKSignUpNeeded.\n");
  2632. ASSERT(pszPath);
  2633. ASSERT(dwPathLen);
  2634. if (NULL == pszPath || 0 == dwPathLen)
  2635. {
  2636. goto IsIEAKSignUpNeededExit;
  2637. }
  2638. //
  2639. // Check if IEAK registry key is set
  2640. //
  2641. {
  2642. RegEntry re(szRegIEAKSettings,HKEY_CURRENT_USER);
  2643. if (ERROR_SUCCESS != re.GetError())
  2644. goto IsIEAKSignUpNeededExit;
  2645. if (0 == re.GetNumber(szREgIEAKNeededKey, 0))
  2646. {
  2647. bRC = FALSE;
  2648. goto IsIEAKSignUpNeededExit;
  2649. }
  2650. }
  2651. //
  2652. // Check to see if IEAK signup page is available.
  2653. //
  2654. {
  2655. RegEntry rePath(szRegPathIexploreAppPath,HKEY_LOCAL_MACHINE);
  2656. if (ERROR_SUCCESS != rePath.GetError())
  2657. goto IsIEAKSignUpNeededExit;
  2658. if (NULL == rePath.GetString(szPathSubKey,pszPath,dwPathLen))
  2659. {
  2660. goto IsIEAKSignUpNeededExit;
  2661. }
  2662. dwPathLen = lstrlen(pszPath);
  2663. ASSERT(dwPathLen);
  2664. }
  2665. //
  2666. // Massage path to point at signup file
  2667. //
  2668. TCHAR *pc, *pcTemp;
  2669. pc = &(pszPath[dwPathLen]);
  2670. pc = CharPrev(pszPath,pc);
  2671. if ('\\' == *pc)
  2672. {
  2673. //
  2674. // add signup part of filename after \ character
  2675. //
  2676. pc = CharNext(pc);
  2677. }
  2678. else if (';' == *pc)
  2679. {
  2680. //
  2681. // overwrite trailing ; character
  2682. //
  2683. // pc = pc
  2684. pcTemp = CharPrev(pszPath,pc);
  2685. //
  2686. // check for trailing \ character and add one if needed
  2687. //
  2688. if ('\\' != *pcTemp)
  2689. {
  2690. *pc = '\\';
  2691. pc = CharNext(pc);
  2692. }
  2693. }
  2694. else
  2695. {
  2696. //
  2697. // The path value contains something we don't understand
  2698. //
  2699. ASSERT(0);
  2700. }
  2701. lstrcpy(pc,szIEAKSignupFilename);
  2702. if (0xFFFFFFFF != GetFileAttributes(pszPath))
  2703. {
  2704. bRC = TRUE;
  2705. }
  2706. IsIEAKSignUpNeededExit:
  2707. if (FALSE == bRC)
  2708. {
  2709. pszPath[0] = '\0';
  2710. }
  2711. return bRC;
  2712. }
  2713. /***************************************************************************
  2714. Function CheckConnectionWizard
  2715. Synopsis This function checks if ICW is present and if it has been run
  2716. before. If it is present but has not been run it does one of
  2717. the following based on the value of dwRunFlags: returns, runs
  2718. the full ICW, or runs the manual path.
  2719. Arguments dwRunFlags is a combination of the following bit flags.
  2720. Value Meaning
  2721. ICW_CHECKSTATUS Check if ICW is present and if it
  2722. has been run.
  2723. ICW_LAUNCHFULL If ICW is present and the full path
  2724. is available, run the full path, if
  2725. possible.
  2726. ICW_LAUNCHMANUAL If ICW is present, run the manual path.
  2727. ICW_USE_SHELLNEXT If the full ICW path will be run, pass the
  2728. value set by SetShellNext to icwconn1 using
  2729. the /shellnext command line flag.
  2730. ICW_FULL_SMARTSTART If ICW is present and the full path
  2731. is available, and ICW_LAUNCHFULL is
  2732. specified, then add /smartstart parameter
  2733. to command line.
  2734. lpdwReturnFlags contains the results of the call. It is a
  2735. combination of the following bit flags.
  2736. Value Meaning
  2737. ICW_FULLPRESENT ICW full path is present on the system.
  2738. ICW_MANUALPRESENT ICW manual path is present. This will
  2739. always be set if ICW_FULLPRESENT is set.
  2740. ICW_ALREADYRUN ICW has already been run to completion
  2741. before.
  2742. ICW_LAUNCHEDFULL The full path of ICW was started.
  2743. ICW_LAUNCHEDMANUAL The manual path of ICW was started.
  2744. Note: The calling application should exit if ICW_LAUNCHEDFULL or
  2745. ICW_LAUNCHEDMANUAL are set. ICW may cause the system to
  2746. reboot if required system software needs to be installed.
  2747. Return ERROR_SUCCESS indicates a successful call.
  2748. Any other value indicates failure.
  2749. ****************************************************************************/
  2750. #define LAUNCHFULL_PARAMETER_SIZE (MAX_PATH + 2 + lstrlen(szICWShellNextFlag) + lstrlen(szICWSmartStartFlag))
  2751. extern "C" DWORD WINAPI CheckConnectionWizard(DWORD dwRunFlags, LPDWORD lpdwReturnFlags)
  2752. {
  2753. DWORD dwRetFlags = 0;
  2754. DWORD dwResult = ERROR_SUCCESS;
  2755. TCHAR *szParameter = NULL;
  2756. HINSTANCE hinst = NULL;
  2757. //
  2758. // ChrisK IE 39452 6/18/97
  2759. // IEAK support of ISP mode
  2760. //
  2761. BOOL fIEAKNeeded = FALSE;
  2762. TCHAR szIEAKPage[MAX_PATH + 1] = TEXT("\0invalid");
  2763. fIEAKNeeded = IsIEAKSignUpNeeded(szIEAKPage,MAX_PATH);
  2764. // Find out if full ICW is installed. Since ICW is bound to the base
  2765. // install of IE, we can just check if IE 3.0 is installed or not.
  2766. // This may change in the future.
  2767. if (IEInstalled())
  2768. dwRetFlags |= ICW_FULLPRESENT;
  2769. // Find out if manual ICW is installed. Since this if part of INETCFG.DLL
  2770. // and it also contains the manual ICW it is always present.
  2771. dwRetFlags |= ICW_MANUALPRESENT;
  2772. // If nothing's installed, exit now
  2773. #if 0 // Always at least manual path
  2774. if (!((dwRetFlags & ICW_FULLPRESENT) || (dwRetFlags & ICW_MANUALPRESENT)))
  2775. goto CheckConnectionWizardExit;
  2776. #endif
  2777. // Find out if ICW has been run
  2778. {
  2779. RegEntry re(szRegPathICWSettings,HKEY_CURRENT_USER);
  2780. dwResult = re.GetError();
  2781. if (ERROR_SUCCESS != dwResult)
  2782. goto CheckConnectionWizardExit;
  2783. if (re.GetNumber(szRegValICWCompleted, 0))
  2784. {
  2785. dwRetFlags |= ICW_ALREADYRUN;
  2786. goto CheckConnectionWizardExit;
  2787. }
  2788. }
  2789. if ((dwRetFlags & ICW_FULLPRESENT) && (dwRunFlags & ICW_LAUNCHFULL))
  2790. {
  2791. #if !defined(WIN16)
  2792. if( dwRunFlags & ICW_USE_SHELLNEXT )
  2793. {
  2794. RegEntry re(szRegPathICWSettings,HKEY_CURRENT_USER);
  2795. dwResult = re.GetError();
  2796. if (ERROR_SUCCESS == dwResult)
  2797. {
  2798. TCHAR szShellNextCmd[MAX_PATH + 1];
  2799. ZeroMemory( szShellNextCmd, sizeof(szShellNextCmd) );
  2800. if( re.GetString(szRegValShellNext, szShellNextCmd, sizeof(szShellNextCmd)) )
  2801. {
  2802. DEBUGMSG("CheckConnectionWizard read ShellNext = %s", szShellNextCmd);
  2803. szParameter = (TCHAR *)GlobalAlloc(GPTR, sizeof(TCHAR)*LAUNCHFULL_PARAMETER_SIZE);
  2804. if( szParameter )
  2805. {
  2806. ZeroMemory( szParameter, sizeof(szParameter) );
  2807. lstrcpy( szParameter, szICWShellNextFlag );
  2808. lstrcat( szParameter, szShellNextCmd );
  2809. //
  2810. // clean up after ourselves
  2811. //
  2812. // 7/9/97 jmazner Olympus #9170
  2813. // Nope, leave the reg key there for the manual path to find.
  2814. // conn1 and man path should clean this up when they finish.
  2815. //re.DeleteValue(szRegValShellNext);
  2816. //
  2817. }
  2818. }
  2819. }
  2820. }
  2821. //
  2822. // ChrisK 5/25/97 Add the /smartstart parameter if appropriate
  2823. //
  2824. if (!fIEAKNeeded && dwRunFlags & ICW_FULL_SMARTSTART)
  2825. {
  2826. //
  2827. // 6/6/97 jmazner Olympus #5927
  2828. //
  2829. //if(IsSmartStart())
  2830. if( SMART_QUITICW == IsSmartStart() )
  2831. {
  2832. //
  2833. // ChrisK Olympus 5902 6/6/97
  2834. // Set completed flag is SmartStart is TRUE
  2835. //
  2836. RegEntry reg(szRegPathICWSettings,HKEY_CURRENT_USER);
  2837. if (ERROR_SUCCESS == (dwResult = reg.GetError()))
  2838. {
  2839. reg.SetValue(szRegValICWCompleted, (DWORD)1);
  2840. }
  2841. dwRetFlags |= ICW_ALREADYRUN;
  2842. goto CheckConnectionWizardExit;
  2843. }
  2844. }
  2845. #endif
  2846. if (!fIEAKNeeded)
  2847. {
  2848. // Launch the full ICW (ICWCONN1.EXE)
  2849. hinst = ShellExecute (NULL, NULL, szFullICWFileName, szParameter, NULL, SW_NORMAL);
  2850. }
  2851. else
  2852. {
  2853. ASSERT(szIEAKPage[0]);
  2854. //
  2855. // Launch IEAK signup
  2856. //
  2857. hinst = ShellExecute (NULL, NULL, szISignupICWFileName, szIEAKPage, NULL, SW_NORMAL);
  2858. }
  2859. if (32 >= (DWORD_PTR)hinst)
  2860. {
  2861. if (NULL == hinst)
  2862. dwResult = ERROR_OUTOFMEMORY;
  2863. else
  2864. dwResult = (DWORD)((DWORD_PTR)hinst);
  2865. goto CheckConnectionWizardExit;
  2866. }
  2867. dwRetFlags |= ICW_LAUNCHEDFULL;
  2868. }
  2869. else if ((dwRetFlags & ICW_MANUALPRESENT) &&
  2870. ((dwRunFlags & ICW_LAUNCHFULL) || (dwRunFlags & ICW_LAUNCHMANUAL)))
  2871. {
  2872. // Launch the manual ICW (INETWIZ.EXE)
  2873. HINSTANCE hinst = ShellExecute (NULL, NULL, szManualICWFileName, NULL, NULL, SW_NORMAL);
  2874. if (32 >= (DWORD)((DWORD_PTR)hinst))
  2875. {
  2876. if (NULL == hinst)
  2877. dwResult = ERROR_OUTOFMEMORY;
  2878. else
  2879. dwResult = (DWORD)((DWORD_PTR)hinst);
  2880. goto CheckConnectionWizardExit;
  2881. }
  2882. dwRetFlags |= ICW_LAUNCHEDMANUAL;
  2883. }
  2884. CheckConnectionWizardExit:
  2885. if( szParameter )
  2886. {
  2887. GlobalFree( szParameter );
  2888. }
  2889. *lpdwReturnFlags = dwRetFlags;
  2890. return dwResult;
  2891. }
  2892. /******
  2893. *
  2894. * InetCreateMailNewsAccount and InetCreateDirectoryService, below, have
  2895. * been obsoleted by the move to the wizard/apprentice model. The Account
  2896. * Manager now owns the UI for mail/news/ldap creation, thus there is no
  2897. * longer a need for these entry points.
  2898. *
  2899. * 4/23/97 jmazner Olympus #3136
  2900. *
  2901. ******/
  2902. /***************************************************************************
  2903. Function InetCreateMailNewsAccount
  2904. Synopsis The InetCreateMailNewsAccount function will create a new Internet
  2905. mail or news account. The user is prompted through a wizard
  2906. interface for the minimum required information to setup a new
  2907. Internet mail or news account.
  2908. Arguments hwndparent is the window handle of the parent for the wizard
  2909. dialogs. If it is NULL the dialogs will be parentless.
  2910. dwConfigType is of the following two enumerated types from ACCTTYPE.
  2911. Value Meaning
  2912. ICW_ACCTMAIL (0) Create a new Internet mail account.
  2913. ICW_ACCTNEWS (1) Create a new Internet news account.
  2914. lpMailNewsInfo is a pointer to a IMNACCTINFO struct. The values
  2915. passed in will be used as defaults and the user's entries will
  2916. be returned in this structure. If this is NULL then ICW will
  2917. use defaults as indicated in parentheses below.
  2918. Return ERROR_SUCCESS indicates a successful call.
  2919. ERROR_CANCELLED indicates the user canceled the wizard.
  2920. Any other value indicates failure.
  2921. ****************************************************************************/
  2922. /***
  2923. extern "C" DWORD WINAPI InetCreateMailNewsAccount(
  2924. HWND hwndParent, //parent of wizard dialogs
  2925. ICW_ACCTTYPE AccountType, //account type
  2926. IMNACCTINFO *lpMailNewsInfo, // mail or news account information
  2927. DWORD dwInFlags // setup flags
  2928. )
  2929. {
  2930. DWORD dwResult = ERROR_SUCCESS;
  2931. DWORD dwFlags = 0;
  2932. // Initialize the wizard
  2933. gpWizardState = new WIZARDSTATE;
  2934. gpUserInfo = new USERINFO;
  2935. gdwRasEntrySize = sizeof(RASENTRY);
  2936. gpRasEntry = (LPRASENTRY) GlobalAlloc(GPTR,gdwRasEntrySize);
  2937. if (!gpWizardState || !gpUserInfo || !gpRasEntry)
  2938. {
  2939. // display an out of memory error
  2940. MsgBox(NULL,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  2941. dwResult = ERROR_OUTOFMEMORY;
  2942. goto InetCreateMailNewsAccountExit;
  2943. }
  2944. // Assign the global defaults pointer so we will use it later
  2945. gpMailNewsInfo = lpMailNewsInfo;
  2946. gfUseMailNewsDefaults = (dwInFlags & ICW_USEDEFAULTS);
  2947. // Set the start page
  2948. switch(AccountType)
  2949. {
  2950. case ICW_ACCTMAIL:
  2951. dwFlags |= RSW_MAILACCT;
  2952. break;
  2953. case ICW_ACCTNEWS:
  2954. dwFlags |= RSW_NEWSACCT;
  2955. break;
  2956. default:
  2957. dwResult = ERROR_INVALID_PARAMETER;
  2958. goto InetCreateMailNewsAccountExit;
  2959. break;
  2960. }
  2961. gfUserFinished = FALSE;
  2962. gfUserCancelled = FALSE;
  2963. RunSignupWizard(dwFlags, hwndParent);
  2964. if (gfUserFinished)
  2965. dwResult = ERROR_SUCCESS;
  2966. else if (gfUserCancelled)
  2967. dwResult = ERROR_CANCELLED;
  2968. else
  2969. dwResult = ERROR_GEN_FAILURE;
  2970. InetCreateMailNewsAccountExit:
  2971. // free global structures
  2972. if (gpWizardState)
  2973. delete gpWizardState;
  2974. if (gpUserInfo)
  2975. delete gpUserInfo;
  2976. if (gpEnumModem)
  2977. delete gpEnumModem;
  2978. if (gpRasEntry)
  2979. GlobalFree(gpRasEntry);
  2980. return dwResult;
  2981. }
  2982. ******/
  2983. /***************************************************************************
  2984. Function InetCreateDirectoryService
  2985. Synopsis The InetCreateDirectoryService function will create a new Internet
  2986. directory service (LDAP account). The user is prompted through a wizard
  2987. interface for the minimum required information to setup the service
  2988. Arguments hwndparent is the window handle of the parent for the wizard
  2989. dialogs. If it is NULL the dialogs will be parentless.
  2990. AccountType should be ICW_ACCTDIRSERV
  2991. lpDirServiceInfo is a pointer to a DIRSERVINFO struct. The values
  2992. passed in will be used as defaults and the user's entries will
  2993. be returned in this structure. If this is NULL then ICW will
  2994. use defaults as indicated in parentheses below.
  2995. Return ERROR_SUCCESS indicates a successful call.
  2996. ERROR_CANCELLED indicates the user canceled the wizard.
  2997. Any other value indicates failure.
  2998. ****************************************************************************/
  2999. /***********
  3000. extern "C" DWORD WINAPI InetCreateDirectoryService(
  3001. HWND hwndParent, // parent of wizard dialogs
  3002. ICW_ACCTTYPE AccountType, // account type
  3003. DIRSERVINFO *lpDirServiceInfo, // LDAP account information
  3004. DWORD dwInFlags // setup flags
  3005. )
  3006. {
  3007. DWORD dwRet = ERROR_SUCCESS;
  3008. DWORD dwFlags = 0;
  3009. // Initialize the wizard
  3010. gpWizardState = new WIZARDSTATE;
  3011. gpUserInfo = new USERINFO;
  3012. gdwRasEntrySize = sizeof(RASENTRY);
  3013. gpRasEntry = (LPRASENTRY) GlobalAlloc(GPTR,gdwRasEntrySize);
  3014. if (!gpWizardState || !gpUserInfo || !gpRasEntry)
  3015. {
  3016. // display an out of memory error
  3017. MsgBox(NULL,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  3018. dwRet = ERROR_OUTOFMEMORY;
  3019. goto InetCreateDirectoryServiceExit;
  3020. }
  3021. // Assign the global defaults pointer so we will use it later
  3022. gpDirServiceInfo = lpDirServiceInfo;
  3023. gfUseDirServiceDefaults = (dwInFlags & ICW_USEDEFAULTS);
  3024. // Set the start page
  3025. switch(AccountType)
  3026. {
  3027. case ICW_ACCTDIRSERV:
  3028. dwFlags |= RSW_DIRSERVACCT;
  3029. break;
  3030. default:
  3031. dwRet = ERROR_INVALID_PARAMETER;
  3032. goto InetCreateDirectoryServiceExit;
  3033. break;
  3034. }
  3035. gfUserFinished = FALSE;
  3036. gfUserCancelled = FALSE;
  3037. RunSignupWizard(dwFlags, hwndParent);
  3038. if (gfUserFinished)
  3039. dwRet = ERROR_SUCCESS;
  3040. else if (gfUserCancelled)
  3041. dwRet = ERROR_CANCELLED;
  3042. else
  3043. dwRet = ERROR_GEN_FAILURE;
  3044. InetCreateDirectoryServiceExit:
  3045. // free global structures
  3046. if (gpWizardState)
  3047. delete gpWizardState;
  3048. if (gpUserInfo)
  3049. delete gpUserInfo;
  3050. if (gpEnumModem)
  3051. delete gpEnumModem;
  3052. if (gpRasEntry)
  3053. GlobalFree(gpRasEntry);
  3054. return dwRet;
  3055. }
  3056. ******/
  3057. #if !defined(WIN16)
  3058. // 4/1/97 ChrisK Olympus 209
  3059. //+----------------------------------------------------------------------------
  3060. // Function: WaitCfgDlgProc
  3061. //
  3062. // Synopsis: Handle busy dialog messages
  3063. //
  3064. // Arguments: standard DialogProc
  3065. //
  3066. // Returns: standard DialogProc
  3067. //
  3068. // History: 4/2/97 ChrisK Created
  3069. //-----------------------------------------------------------------------------
  3070. INT_PTR CALLBACK WaitCfgDlgProc(
  3071. HWND hDlg,
  3072. UINT uMsg,
  3073. WPARAM wParam,
  3074. LPARAM lParam
  3075. )
  3076. {
  3077. HWND hwndAni;
  3078. switch (uMsg)
  3079. {
  3080. case WM_DESTROY:
  3081. hwndAni = GetDlgItem(hDlg,IDC_ANIMATE);
  3082. if (hwndAni)
  3083. {
  3084. Animate_Stop(hwndAni);
  3085. Animate_Close(hwndAni);
  3086. hwndAni = NULL;
  3087. }
  3088. break;
  3089. case WM_INITDIALOG:
  3090. // Loop animation forever.
  3091. hwndAni = GetDlgItem(hDlg,IDC_ANIMATE);
  3092. if (hwndAni)
  3093. {
  3094. Animate_Open(hwndAni,MAKEINTRESOURCE(IDA_WAITINGCONFIG));
  3095. Animate_Play(hwndAni, 0, -1, -1);
  3096. hwndAni = NULL;
  3097. }
  3098. break;
  3099. }
  3100. return FALSE;
  3101. }
  3102. //+----------------------------------------------------------------------------
  3103. // Function: WaitCfgInit
  3104. //
  3105. // Synopsis: Create, center, and display busy dialog
  3106. //
  3107. // Arguments: hwndParent - handle of parent window
  3108. // dwIDS - ID of string resource to display
  3109. //
  3110. // Return: handle to busy window
  3111. //
  3112. // History: 4/2/97 ChrisK Created
  3113. //-----------------------------------------------------------------------------
  3114. HWND WaitCfgInit(HWND hwndParent, DWORD dwIDS)
  3115. {
  3116. HWND hwnd;
  3117. RECT MyRect;
  3118. RECT DTRect;
  3119. TCHAR szMessage[255];
  3120. // Create dialog
  3121. hwnd = CreateDialog (ghInstance, MAKEINTRESOURCE(IDD_CONFIGWAIT), hwndParent, WaitCfgDlgProc);
  3122. if (NULL != hwnd)
  3123. {
  3124. // Center dialog on desktop
  3125. GetWindowRect(hwnd, &MyRect);
  3126. GetWindowRect(GetDesktopWindow(), &DTRect);
  3127. MoveWindow(hwnd, (DTRect.right - (MyRect.right - MyRect.left)) / 2, (DTRect.bottom - (MyRect.bottom - MyRect.top)) /2,
  3128. (MyRect.right - MyRect.left), (MyRect.bottom - MyRect.top), FALSE);
  3129. // Load string for message
  3130. szMessage[0] = '\0';
  3131. LoadSz(dwIDS,szMessage,sizeof(szMessage)-1);
  3132. SetDlgItemText(hwnd,IDC_LBLWAITCFG,szMessage);
  3133. // Display dialog and paint text
  3134. ShowWindow(hwnd,SW_SHOW);
  3135. UpdateWindow(hwnd);
  3136. }
  3137. return hwnd;
  3138. }
  3139. //+----------------------------------------------------------------------------
  3140. // Function: SetShellNext
  3141. //
  3142. // Synopsis: Sets the ShellNext registry key with the passed in value. This
  3143. // key is passed to icwconn1 via the /shellnext command line option
  3144. // if the ICW_USE_SHELLNEXT option is specified.
  3145. //
  3146. // Arguments: szShellNext -- pointer to a string containing the /shellnext cmd.
  3147. // **should have length <= MAX_PATH**
  3148. //
  3149. // Return: a win32 result code. ERROR_SUCCESS indicates success.
  3150. //
  3151. // History: 5/21/97 jmazner Created for Olympus bug #4157
  3152. //-----------------------------------------------------------------------------
  3153. #ifdef UNICODE
  3154. extern "C" DWORD WINAPI SetShellNextA(CHAR *szShellNext)
  3155. {
  3156. TCHAR* szShellNextW = new TCHAR[INTERNET_MAX_URL_LENGTH+1];
  3157. DWORD dwRet = ERROR_INVALID_PARAMETER;
  3158. if (szShellNextW)
  3159. {
  3160. mbstowcs(szShellNextW, szShellNext, lstrlenA(szShellNext)+1);
  3161. dwRet = SetShellNextW(szShellNextW);
  3162. delete [] szShellNextW;
  3163. }
  3164. return dwRet;
  3165. }
  3166. extern "C" DWORD WINAPI SetShellNextW(WCHAR *szShellNext)
  3167. #else
  3168. extern "C" DWORD WINAPI SetShellNextA(CHAR *szShellNext)
  3169. #endif
  3170. {
  3171. DWORD dwResult = ERROR_SUCCESS;
  3172. if( !szShellNext || !szShellNext[0] )
  3173. {
  3174. DEBUGMSG("SetShellNext got an invalid parameter\n");
  3175. return ERROR_INVALID_PARAMETER;
  3176. }
  3177. RegEntry re(szRegPathICWSettings,HKEY_CURRENT_USER);
  3178. dwResult = re.GetError();
  3179. if (ERROR_SUCCESS == dwResult)
  3180. {
  3181. if( ERROR_SUCCESS == re.SetValue(szRegValShellNext, szShellNext) )
  3182. {
  3183. DEBUGMSG("SetShellNext set ShellNext = %s", szShellNext);
  3184. }
  3185. else
  3186. {
  3187. dwResult = re.GetError();
  3188. }
  3189. }
  3190. return dwResult;
  3191. }
  3192. #ifdef OLD_SMART_START
  3193. #define IE4_PROXYSERVER_SETTING_KEY "ProxyServer"
  3194. #define IE4_PROXYENABLE_SETTING_KEY "ProxyEnable"
  3195. #define IE4_SETTINGS_STARTPAGE "Start Page"
  3196. #define IE4_SETTINGS_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
  3197. #define IE4_SETTINGS_MAIN "Software\\Microsoft\\Internet Explorer\\Main"
  3198. #define INETCFG_INETGETAUTODIAL "InetGetAutodial"
  3199. #define INETCFG_INETNEEDSYSTEMCOMPONENTS "InetNeedSystemComponents"
  3200. typedef HRESULT (WINAPI* PFNINETNEEDSYSTEMCOMPONENTS)(DWORD,LPBOOL);
  3201. typedef HRESULT (WINAPI* PFNINETGETAUTODIAL)(LPBOOL,LPTSTR,DWORD);
  3202. typedef DWORD (WINAPI* PFNRASGETAUTODIALADDRESS)(LPTSTR,LPDWORD,LPRASAUTODIALENTRY,LPDWORD,LPDWORD);
  3203. #define MIN_HTTP_ADDRESS (sizeof(SMART_HTTP) + 1)
  3204. #define SMART_HTTP TEXT("http://")
  3205. //+----------------------------------------------------------------------------
  3206. //
  3207. // Function: SmartStartNetcard
  3208. //
  3209. // Synopsis: Check machine to see if it is setup to connect via a netcard
  3210. // and proxy
  3211. //
  3212. // Arguments: none
  3213. //
  3214. // Returns: TRUE - run ICW; FALSE - quit now
  3215. //
  3216. // History: 5/10/97 ChrisK Created
  3217. //
  3218. //-----------------------------------------------------------------------------
  3219. BOOL SmartStartNetcard()
  3220. {
  3221. BOOL bResult = FALSE;
  3222. HKEY hkey = NULL;
  3223. DWORD dwSize = 0;
  3224. DWORD dwData = 0;
  3225. BOOL bRC = SMART_RUNICW;
  3226. DEBUGMSG("INETCFG: SmartStartNetcard\n");
  3227. //
  3228. // Call Inetcfg to check for LAN card and TCP binding to that card
  3229. //
  3230. if (ERROR_SUCCESS != InetNeedSystemComponents(INETCFG_INSTALLLAN,
  3231. &bResult) || bResult)
  3232. {
  3233. DEBUGMSG("INETCFG: SmartStart not Netcard or not bound.\n");
  3234. goto SmartStartNetcardExit;
  3235. }
  3236. //
  3237. // Check to see if there are IE4 proxy settings
  3238. //
  3239. hkey = NULL;
  3240. if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER,
  3241. IE4_SETTINGS_KEY,
  3242. &hkey)
  3243. || NULL == hkey)
  3244. {
  3245. DEBUGMSG("INETCFG: SmartSmart IE4 Proxy key is not available.\n");
  3246. goto SmartStartNetcardExit;
  3247. }
  3248. dwSize = sizeof(dwData);
  3249. if (ERROR_SUCCESS != RegQueryValueEx(hkey,
  3250. IE4_PROXYENABLE_SETTING_KEY,
  3251. NULL, // lpReserved
  3252. NULL, // lpType
  3253. (LPBYTE)&dwData, // lpData
  3254. &dwSize)
  3255. || 0 == dwData)
  3256. {
  3257. DEBUGMSG("INETCFG: SmartStart IE4 Proxy not enabled.\n");
  3258. goto SmartStartNetcardExit;
  3259. }
  3260. if (ERROR_SUCCESS != RegQueryValueEx(hkey,
  3261. IE4_PROXYSERVER_SETTING_KEY,
  3262. NULL, // lpReserved
  3263. NULL, // lpType
  3264. NULL, // lpData
  3265. &dwSize)
  3266. || 1 >= dwSize) // note: a single null character is length 1
  3267. {
  3268. DEBUGMSG("INETCFG: SmartStart IE 4 Proxy server not available.\n");
  3269. goto SmartStartNetcardExit;
  3270. }
  3271. //
  3272. // The user appears to have a valid configuration. Do not
  3273. // run the ICW.
  3274. //
  3275. bRC = SMART_QUITICW;
  3276. SmartStartNetcardExit:
  3277. if (NULL != hkey)
  3278. {
  3279. RegCloseKey(hkey);
  3280. hkey = NULL;
  3281. }
  3282. return bRC;
  3283. }
  3284. //+----------------------------------------------------------------------------
  3285. //
  3286. // Function: IsSmartPPPConnectoid
  3287. //
  3288. // Synopsis: Given a connectoid name determine if the framing protocol is PPP
  3289. //
  3290. // Arguments: lpszEntry - name of connectoid
  3291. //
  3292. // Returns: TRUE - the framing protocol is PPP; FALSE - it is something else
  3293. //
  3294. // History: 5/10/97 ChrisK Created
  3295. //
  3296. //-----------------------------------------------------------------------------
  3297. BOOL IsSmartPPPConnectoid(LPTSTR lpszEntry)
  3298. {
  3299. LPRASENTRY lpRasEntry = NULL;
  3300. DWORD dwRasEntrySize = 0;
  3301. LPRASDEVINFO lpRasDevInfo = NULL;
  3302. DWORD dwRasDevInfoSize = 0;
  3303. DWORD dwSize;
  3304. BOOL bRC = FALSE;
  3305. DEBUGMSG("INETCFG: IsSmartPPPConnectoid\n");
  3306. //
  3307. // Check for PPP connectoid
  3308. //
  3309. //
  3310. // ChrisK Olympus 6055 6/7/97
  3311. // Make sure RNA dll functions are loaded, otherwise
  3312. // GetEntry will assert.
  3313. //
  3314. if (ERROR_SUCCESS != EnsureRNALoaded() ||
  3315. ERROR_SUCCESS != GetEntry(&lpRasEntry,
  3316. &dwRasEntrySize,
  3317. lpszEntry) ||
  3318. RASFP_Ppp != lpRasEntry->dwFramingProtocol)
  3319. {
  3320. goto IsSmartPPPConnectoidExit;
  3321. }
  3322. else
  3323. {
  3324. //
  3325. // The user appears to have a working modem connectoid
  3326. // so skip the ICW
  3327. //
  3328. bRC = TRUE;
  3329. goto IsSmartPPPConnectoidExit;
  3330. }
  3331. IsSmartPPPConnectoidExit:
  3332. //
  3333. // Release memory
  3334. //
  3335. if (NULL != lpRasEntry)
  3336. {
  3337. GlobalFree(lpRasEntry);
  3338. lpRasEntry = NULL;
  3339. }
  3340. if (NULL != lpRasDevInfo)
  3341. {
  3342. GlobalFree(lpRasDevInfo);
  3343. lpRasDevInfo = NULL;
  3344. }
  3345. return bRC;
  3346. }
  3347. //+----------------------------------------------------------------------------
  3348. //
  3349. // Function: SmartStartPPPConnectoidNT
  3350. //
  3351. // Synopsis: Check that the connectoid for the address of the start page is
  3352. // a PPP connectoid
  3353. //
  3354. // Arguments:
  3355. //
  3356. // Returns: TRUE - run ICW; FALSE - quit NOW
  3357. //
  3358. // History: 5/10/97 ChrisK Created
  3359. //
  3360. //-----------------------------------------------------------------------------
  3361. BOOL SmartStartPPPConnectoidNT()
  3362. {
  3363. BOOL bRC = SMART_RUNICW;
  3364. HKEY hkey;
  3365. TCHAR szStartPage[1024];
  3366. TCHAR *pchFrom, *pchTo;
  3367. HINSTANCE hRASAPI32;
  3368. LPRASAUTODIALENTRY lpRasAutoDialEntry = NULL;
  3369. DWORD dwSize=0;
  3370. DWORD dwNum=0;
  3371. FARPROC fp = NULL;
  3372. DEBUGMSG("INETCFG: SmartStartPPPConnectoidNT\n");
  3373. //
  3374. // Read start page from registry
  3375. //
  3376. if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER,
  3377. IE4_SETTINGS_MAIN,
  3378. &hkey) && hkey)
  3379. {
  3380. goto SmartStartPPPConnectoidNTExit;
  3381. }
  3382. if (ERROR_SUCCESS != RegQueryValueEx(hkey,
  3383. IE4_SETTINGS_STARTPAGE,
  3384. NULL, //lpReserved
  3385. NULL, //lpType
  3386. (LPBYTE)szStartPage,//lpData
  3387. &dwSize) //lpcbData
  3388. && dwSize >= MIN_HTTP_ADDRESS)
  3389. {
  3390. goto SmartStartPPPConnectoidNTExit;
  3391. }
  3392. //
  3393. // Parse server name out of start page URL and save it in szStartPage
  3394. //
  3395. if (2 != CompareString(LOCALE_SYSTEM_DEFAULT,
  3396. NORM_IGNORECASE,
  3397. szStartPage,
  3398. lstrlen(SMART_HTTP),
  3399. SMART_HTTP,
  3400. lstrlen(SMART_HTTP)))
  3401. {
  3402. goto SmartStartPPPConnectoidNTExit;
  3403. }
  3404. pchFrom = &szStartPage[sizeof(SMART_HTTP)];
  3405. pchTo = &szStartPage[0];
  3406. while (*pchFrom && '/' != *pchFrom)
  3407. {
  3408. *pchTo++ = *pchFrom++;
  3409. }
  3410. *pchTo = '\0';
  3411. //
  3412. // Look up address in RasAutodial database
  3413. //
  3414. if (NULL == (hRASAPI32 = LoadLibrary("rasapi32.dll")))
  3415. {
  3416. DEBUGMSG("INETCFG: rasapi32.dll didn't load.\n");
  3417. goto SmartStartPPPConnectoidNTExit;
  3418. }
  3419. #ifdef UNICODE
  3420. if (NULL == (fp = GetProcAddress(hRASAPI32,"RasGetAutodialAddressW")))
  3421. #else
  3422. if (NULL == (fp = GetProcAddress(hRASAPI32,"RasGetAutodialAddressA")))
  3423. #endif
  3424. {
  3425. DEBUGMSG("INETCFG: RasGetAutodialAddressA didn't load.\n");
  3426. goto SmartStartPPPConnectoidNTExit;
  3427. }
  3428. if (ERROR_SUCCESS != ((PFNRASGETAUTODIALADDRESS)fp)(szStartPage,
  3429. NULL, // lpdwReserved
  3430. NULL, // lpAutoDialEntries
  3431. &dwSize, // lpdwcbAutoDialEntries
  3432. &dwNum) // lpdwcAutoDialEntries
  3433. || 0 == dwNum)
  3434. {
  3435. goto SmartStartPPPConnectoidNTExit;
  3436. }
  3437. if (NULL == (lpRasAutoDialEntry = (LPRASAUTODIALENTRY)GlobalAlloc(GPTR,dwSize)))
  3438. {
  3439. goto SmartStartPPPConnectoidNTExit;
  3440. }
  3441. lpRasAutoDialEntry->dwSize = dwSize;
  3442. if (ERROR_SUCCESS != ((PFNRASGETAUTODIALADDRESS)fp)(szStartPage,
  3443. NULL, // lpdwReserved
  3444. lpRasAutoDialEntry, // lpAutoDialEntries
  3445. &dwSize, // lpdwcbAutoDialEntries
  3446. &dwNum)) // lpdwcAutoDialEntries
  3447. {
  3448. goto SmartStartPPPConnectoidNTExit;
  3449. }
  3450. //
  3451. // Determine if the connectoid is PPP
  3452. //
  3453. if (IsSmartPPPConnectoid(lpRasAutoDialEntry->szEntry))
  3454. {
  3455. bRC = SMART_QUITICW;
  3456. }
  3457. SmartStartPPPConnectoidNTExit:
  3458. if (hkey)
  3459. {
  3460. RegCloseKey(hkey);
  3461. hkey = NULL;
  3462. }
  3463. return bRC;
  3464. }
  3465. //+----------------------------------------------------------------------------
  3466. //
  3467. // Function: SmartStartPPPConnectoid95
  3468. //
  3469. // Synopsis: Check that the connectoid set in the autodial setting is a PPP
  3470. // connectoid
  3471. //
  3472. // Arguments:
  3473. //
  3474. // Returns: TRUE - run ICW; FALSE - quit NOW
  3475. //
  3476. // History: 5/10/97 ChrisK Created
  3477. //
  3478. //-----------------------------------------------------------------------------
  3479. BOOL SmartStartPPPConnectoid95()
  3480. {
  3481. BOOL bAutodialEnabled = FALSE;
  3482. CHAR szAutodialName[RAS_MaxEntryName + 1];
  3483. DWORD dwSize;
  3484. BOOL bRC = SMART_RUNICW;
  3485. DEBUGMSG("INETCFG: SmartStartPPPConnectoid95\n");
  3486. //
  3487. // Get Autodial connectoid
  3488. //
  3489. dwSize = RAS_MaxEntryName;
  3490. if (ERROR_SUCCESS != InetGetAutodial(&bAutodialEnabled,
  3491. szAutodialName,
  3492. dwSize) ||
  3493. !bAutodialEnabled ||
  3494. 0 == lstrlen(szAutodialName))
  3495. {
  3496. goto SmartStartPPPConnectoid95Exit;
  3497. }
  3498. //
  3499. // Determine if the connectoid is PPP
  3500. //
  3501. if (IsSmartPPPConnectoid(szAutodialName))
  3502. {
  3503. bRC = SMART_QUITICW;
  3504. }
  3505. SmartStartPPPConnectoid95Exit:
  3506. return bRC;
  3507. }
  3508. //+----------------------------------------------------------------------------
  3509. //
  3510. // Function: AtLeastOneTAPILocation
  3511. //
  3512. // Synopsis: Check machine to verify that there is at least 1 tapi dialing
  3513. // location
  3514. //
  3515. // Arguments: none
  3516. //
  3517. // Returns: TRUE
  3518. //
  3519. // History: 3 18 98 donaldm
  3520. //
  3521. //-----------------------------------------------------------------------------
  3522. BOOL AtLeastOneTAPILocation()
  3523. {
  3524. HKEY hkey;
  3525. BOOL bRet = FALSE;
  3526. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  3527. REGSTR_PATH_TELEPHONYLOCATIONS,
  3528. 0,
  3529. KEY_ALL_ACCESS,
  3530. &hkey))
  3531. {
  3532. DWORD dwSubKeys = 0;
  3533. if (ERROR_SUCCESS == RegQueryInfoKey(hkey,
  3534. NULL,
  3535. NULL,
  3536. NULL,
  3537. &dwSubKeys,
  3538. NULL,
  3539. NULL,
  3540. NULL,
  3541. NULL,
  3542. NULL,
  3543. NULL,
  3544. NULL))
  3545. {
  3546. // If there are any subkeys under locaitons, then there is at least 1
  3547. if (dwSubKeys)
  3548. bRet = TRUE;
  3549. }
  3550. RegCloseKey(hkey);
  3551. }
  3552. return(bRet);
  3553. }
  3554. //+----------------------------------------------------------------------------
  3555. //
  3556. // Function: SmartStartModem
  3557. //
  3558. // Synopsis: Check machine to verify that there is a modem and an autodial
  3559. // connectoid
  3560. //
  3561. // Arguments: none
  3562. //
  3563. // Returns: TRUE - run ICW; FALSE - quit now
  3564. //
  3565. // History: 5/10/97 ChrisK Created
  3566. //
  3567. //-----------------------------------------------------------------------------
  3568. BOOL SmartStartModem()
  3569. {
  3570. BOOL bResult = FALSE;
  3571. DWORD dwSize = 0;
  3572. BOOL bRC = SMART_RUNICW;
  3573. FARPROC fp;
  3574. DEBUGMSG("INETCFG: SmartStartModem\n");
  3575. //
  3576. // Call Inetcfg to see if a modem is properly installed with TCP
  3577. //
  3578. if (ERROR_SUCCESS == InetNeedSystemComponents(INETCFG_INSTALLDIALUP,
  3579. &bResult)
  3580. && !bResult)
  3581. {
  3582. //
  3583. // Check to see if Dial-Up networking/RAS/RNA is install
  3584. //
  3585. if (ERROR_SUCCESS == InetNeedSystemComponents(INETCFG_INSTALLRNA,
  3586. &bResult)
  3587. && !bResult)
  3588. {
  3589. // DONALDM: GETCON bug 94. If there are no tapi locations, then
  3590. // we can fail smart start, because there is no way the use
  3591. // is connected. We want to bail here because InetNeedModem will call
  3592. // RasEnumDevices, which will pop up the TAPI locations dialog
  3593. if (AtLeastOneTAPILocation())
  3594. {
  3595. //
  3596. // ChrisK Olympus 6324 6/11/97
  3597. // Need to explicitly check for modem
  3598. //
  3599. if (ERROR_SUCCESS == InetNeedModem(&bResult) &&
  3600. !bResult)
  3601. {
  3602. if (IsNT())
  3603. {
  3604. //
  3605. // Check that Ras services are running
  3606. //
  3607. //!JACOBBUGBUG!
  3608. if (ERROR_SUCCESS != InetStartServices())
  3609. {
  3610. goto SmartStartNetcardExit;
  3611. }
  3612. bRC = SmartStartPPPConnectoidNT();
  3613. }
  3614. else
  3615. {
  3616. bRC = SmartStartPPPConnectoid95();
  3617. }
  3618. }
  3619. }
  3620. }
  3621. }
  3622. SmartStartNetcardExit:
  3623. return bRC;
  3624. }
  3625. //+----------------------------------------------------------------------------
  3626. //
  3627. // Function: IsSmartStart
  3628. //
  3629. // Synopsis: This function will determine if the ICW should be run. The
  3630. // decision is made based on the current state of the user's machine.
  3631. //
  3632. // Arguments: none
  3633. //
  3634. // Returns: TRUE - run ICW; FALSE - quit now
  3635. //
  3636. // History: 5/8/97 ChrisK Created
  3637. //
  3638. //-----------------------------------------------------------------------------
  3639. extern "C" DWORD WINAPI IsSmartStart()
  3640. {
  3641. BOOL bRC = SMART_RUNICW;
  3642. BOOL bResult;
  3643. DEBUGMSG("INETCFG: IsSmartStart\n");
  3644. if (IsNT())
  3645. {
  3646. DEBUGMSG("INETCFG: SmartStart not enabled on NT.\n");
  3647. goto IsSmartStartExit;
  3648. }
  3649. //
  3650. // #1. Check to see if TCP is installed
  3651. //
  3652. bResult = FALSE;
  3653. if (ERROR_SUCCESS != InetNeedSystemComponents(INETCFG_INSTALLTCPONLY,
  3654. &bResult) || bResult)
  3655. {
  3656. DEBUGMSG("INETCFG: SmartStart TCP is missing\n");
  3657. goto IsSmartStartExit;
  3658. }
  3659. //
  3660. // #2. Check to see if there is a netcard installed
  3661. //
  3662. if (SMART_QUITICW == (bRC = SmartStartNetcard()))
  3663. {
  3664. DEBUGMSG("INETCFG: SmartStart LAN setup found.\n");
  3665. goto IsSmartStartExit;
  3666. }
  3667. //
  3668. // #3. Check to see if there is a modem installed
  3669. //
  3670. bRC = SmartStartModem();
  3671. if (SMART_QUITICW == bRC)
  3672. {
  3673. DEBUGMSG("INETCFG: SmartStart Modem setup found.\n");
  3674. }
  3675. else
  3676. {
  3677. DEBUGMSG("INETCFG: SmartStart no valid setup found.\n");
  3678. }
  3679. IsSmartStartExit:
  3680. return bRC;
  3681. }
  3682. #endif // OLD_SMART_START
  3683. //+----------------------------------------------------------------------------
  3684. //
  3685. // Function: IsSmartStartEx
  3686. //
  3687. // Synopsis: This function will determine if the ICW should be run. The
  3688. // decision is made based on the current state of the user's machine.
  3689. //
  3690. // Arguments: none
  3691. //
  3692. // Returns: TRUE - run ICW; FALSE - quit now
  3693. //
  3694. // History: 5/8/97 ChrisK Created
  3695. //
  3696. //-----------------------------------------------------------------------------
  3697. typedef DWORD (WINAPI *PFNInternetGetConnectedState) (LPDWORD, DWORD);
  3698. typedef DWORD (WINAPI *PFNInternetGetConnectedStateEx) (LPDWORD, LPTSTR, DWORD, DWORD);
  3699. extern "C" DWORD WINAPI IsSmartStartEx(LPTSTR lpszConnectionName, DWORD dwBufLen)
  3700. {
  3701. DEBUGMSG("INETCFG: IsSmartStartEx\n");
  3702. BOOL bRC = SMART_RUNICW;
  3703. DWORD dwConnectedFlags = 0;
  3704. HINSTANCE hWinInet = LoadLibrary(TEXT("wininet.dll"));
  3705. if (hWinInet)
  3706. {
  3707. PFNInternetGetConnectedState pfnInternetGetConnectedState = NULL;
  3708. PFNInternetGetConnectedStateEx pfnInternetGetConnectedStateEx = NULL;
  3709. #ifdef UNICODE
  3710. pfnInternetGetConnectedStateEx = (PFNInternetGetConnectedStateEx)GetProcAddress(hWinInet,"InternetGetConnectedStateExW");
  3711. #else
  3712. pfnInternetGetConnectedStateEx = (PFNInternetGetConnectedStateEx)GetProcAddress(hWinInet,"InternetGetConnectedStateEx");
  3713. #endif
  3714. pfnInternetGetConnectedState = (PFNInternetGetConnectedState)GetProcAddress(hWinInet,"InternetGetConnectedState");
  3715. if (pfnInternetGetConnectedStateEx)
  3716. {
  3717. pfnInternetGetConnectedStateEx(&dwConnectedFlags,
  3718. lpszConnectionName,
  3719. dwBufLen,
  3720. 0);
  3721. }
  3722. else if(pfnInternetGetConnectedState)
  3723. {
  3724. pfnInternetGetConnectedState(&dwConnectedFlags, 0);
  3725. }
  3726. FreeLibrary(hWinInet);
  3727. }
  3728. // Existing connectoin is determined by existing modem or proxy, no need to run ICW
  3729. // Check to see if there is a MODEM or PROXY connection
  3730. if (dwConnectedFlags &
  3731. (INTERNET_CONNECTION_CONFIGURED | INTERNET_CONNECTION_LAN |
  3732. INTERNET_CONNECTION_PROXY | INTERNET_CONNECTION_MODEM
  3733. )
  3734. )
  3735. {
  3736. bRC = SMART_QUITICW;
  3737. }
  3738. return bRC;
  3739. }
  3740. //+----------------------------------------------------------------------------
  3741. //
  3742. // Function: IsSmartStart
  3743. //
  3744. // Synopsis: This function will determine if the ICW should be run. The
  3745. // decision is made based on the current state of the user's machine.
  3746. //
  3747. // Arguments: none
  3748. //
  3749. // Returns: TRUE - run ICW; FALSE - quit now
  3750. //
  3751. // History: 5/8/97 ChrisK Created
  3752. //
  3753. //-----------------------------------------------------------------------------
  3754. extern "C" DWORD WINAPI IsSmartStart()
  3755. {
  3756. return IsSmartStartEx(NULL, 0);
  3757. }
  3758. //*******************************************************************
  3759. //
  3760. // FUNCTION: SetAutoProxyConnectoid
  3761. //
  3762. // PURPOSE: This function will set the enable/disable auto
  3763. // proxy settings in creating connectoid.
  3764. //
  3765. // PARAMETERS: fEnable - If set to TRUE, proxy will be enabled.
  3766. // If set to FALSE, proxy will be disabled.
  3767. //
  3768. //*******************************************************************
  3769. HRESULT WINAPI SetAutoProxyConnectoid( BOOL bEnable)
  3770. {
  3771. g_bUseAutoProxyforConnectoid = bEnable;
  3772. return ERROR_SUCCESS;
  3773. }
  3774. #endif //!WIN16