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.

927 lines
29 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // INTROUI.C - Functions for introductory Wizard pages
  7. //
  8. // HISTORY:
  9. //
  10. // 12/22/94 jeremys Created.
  11. // 96/03/07 markdu Use global modem enum object (gpEnumModem) for
  12. // all modem stuff (only need to enum once unless we add a modem)
  13. // 96/03/10 markdu Moved all references to modem name into RASENTRY.
  14. // 96/03/11 markdu Check new CLIENTCONFIG flags before installing
  15. // RNA and TCP.
  16. // 96/03/16 markdu Use ReInit member function to re-enumerate modems.
  17. // 96/03/22 markdu Work around problem with fInstallMail to allow the
  18. // user to decide whether to install mail.
  19. // 96/03/22 markdu Always display both modem and LAN options, regardless
  20. // of what hardware is present.
  21. // 96/03/22 markdu Remove IP setup from LAN path.
  22. // 96/03/23 markdu Replaced CLIENTINFO references with CLIENTCONFIG.
  23. // 96/03/24 markdu Return error values from EnumerateModems().
  24. // 96/03/25 markdu If a fatal error occurs, set gfQuitWizard.
  25. // 96/04/04 markdu Added pfNeedsRestart to WarnIfServerBound
  26. // 96/04/06 markdu Moved CommitConfigurationChanges call to last page.
  27. // 96/05/06 markdu NASH BUG 15637 Removed unused code.
  28. // 96/05/06 markdu NASH BUG 21165 Reordered page logic.
  29. // 96/05/14 markdu NASH BUG 21704 Do not install TCP/IP on LAN path.
  30. // 96/05/20 markdu MSN BUG 8551 Check for reboot when installing
  31. // PPPMAC and TCP/IP.
  32. // 96/05/25 markdu Use ICFG_ flags for lpNeedDrivers and lpInstallDrivers.
  33. // 96/05/27 markdu Use lpIcfgInstallInetComponents and lpIcfgNeedInetComponents.
  34. // 96/09/13 valdonb Remove welcome dialog
  35. //
  36. #include "wizard.h"
  37. #include "interwiz.h"
  38. #include "icwextsn.h"
  39. #include "icwaprtc.h"
  40. #include "imnext.h"
  41. UINT GetModemPage(HWND hDlg);
  42. VOID EnableWizard(HWND hDlg,BOOL fEnable);
  43. HRESULT EnumerateModems(HWND hwndParent, ENUM_MODEM** ppEnumModem);
  44. BOOL IsMoreThanOneModemInstalled(ENUM_MODEM* pEnumModem);
  45. BOOL IsModemInstalled(ENUM_MODEM* pEnumModem);
  46. extern ICFGINSTALLSYSCOMPONENTS lpIcfgInstallInetComponents;
  47. extern ICFGNEEDSYSCOMPONENTS lpIcfgNeedInetComponents;
  48. extern ICFGGETLASTINSTALLERRORTEXT lpIcfgGetLastInstallErrorText;
  49. BOOL FGetSystemShutdownPrivledge();
  50. BOOL g_bSkipMultiModem = FALSE;
  51. int nCurrentModemSel = 0;
  52. // from commctrl defines...
  53. #define IDD_BACK 0x3023
  54. #define IDD_NEXT 0x3024
  55. //*******************************************************************
  56. //
  57. // Function GetDeviceSelectedByUser
  58. //
  59. // Synopsis Get the name of the RAS device that the user had
  60. // already picked
  61. //
  62. // Arguements szKey - name of sub key
  63. // szBuf - pointer to buffer
  64. // dwSize - size of buffer
  65. //
  66. // Return TRUE - success
  67. //
  68. // History 10/21/96 VYung Created
  69. //*******************************************************************
  70. BOOL GetDeviceSelectedByUser (LPTSTR szKey, LPTSTR szBuf, DWORD dwSize)
  71. {
  72. BOOL bRC = FALSE;
  73. HKEY hkey = NULL;
  74. DWORD dwType = 0;
  75. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,ISIGNUP_KEY,&hkey))
  76. {
  77. if (ERROR_SUCCESS == RegQueryValueEx(hkey,szKey,0,&dwType,
  78. (LPBYTE)szBuf,&dwSize))
  79. bRC = TRUE;
  80. }
  81. if (hkey)
  82. RegCloseKey(hkey);
  83. return bRC;
  84. }
  85. /*******************************************************************
  86. NAME: HowToConnectInitProc
  87. SYNOPSIS: Called when "How to Connect" page is displayed
  88. ENTRY: hDlg - dialog window
  89. fFirstInit - TRUE if this is the first time the dialog
  90. is initialized, FALSE if this InitProc has been called
  91. before (e.g. went past this page and backed up)
  92. ********************************************************************/
  93. BOOL CALLBACK HowToConnectInitProc(HWND hDlg,BOOL fFirstInit)
  94. {
  95. // If we were started by inetwiz.exe, there is nothing to
  96. // go back to, so only show the "next" button
  97. // (actually, this will only disable the back button, not hide it.)
  98. if (!(gpWizardState->dwRunFlags & (RSW_NOFREE | RSW_APPRENTICE) ))
  99. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT);
  100. if (fFirstInit)
  101. {
  102. // initialize radio buttons
  103. CheckDlgButton(hDlg,IDC_CONNECT_BY_PHONE,
  104. CONNECT_RAS == gpUserInfo->uiConnectionType);
  105. CheckDlgButton(hDlg,IDC_CONNECT_BY_LAN,
  106. CONNECT_LAN == gpUserInfo->uiConnectionType);
  107. CheckDlgButton(hDlg,IDC_CONNECT_MANUAL,
  108. CONNECT_MANUAL == gpUserInfo->uiConnectionType);
  109. // Normandy 11970 ChrisK - we need a different title if launched from
  110. // mail or news configuration
  111. if ( (gpWizardState->dwRunFlags & RSW_APPRENTICE))
  112. {
  113. if (!g_fIsExternalWizard97)
  114. {
  115. TCHAR szTitle[MAX_RES_LEN+1];
  116. if (LoadSz(IDS_BEGINMANUAL_ALTERNATE,szTitle,sizeof(szTitle)))
  117. SetWindowText (GetDlgItem(hDlg,IDC_LBLTITLE), szTitle);
  118. }
  119. }
  120. else
  121. {
  122. // if we're not here via the apprentice interface, hide the
  123. // manual connect option
  124. ASSERT( CONNECT_MANUAL != gpUserInfo->uiConnectionType );
  125. ShowWindow( GetDlgItem(hDlg,IDC_CONNECT_MANUAL), SW_HIDE);
  126. }
  127. // load in strings for the description paragraph
  128. TCHAR szWhole[ (2 * MAX_RES_LEN) + 1] = TEXT("\0");
  129. TCHAR szTemp[ MAX_RES_LEN + 1] = TEXT("nothing\0");
  130. LoadSz(IDS_HOWTOCONNECT_DESC1,szTemp,sizeof(szTemp));
  131. lstrcat( szWhole, szTemp );
  132. LoadSz(IDS_HOWTOCONNECT_DESC2,szTemp,sizeof(szTemp));
  133. lstrcat( szWhole, szTemp );
  134. SetWindowText (GetDlgItem(hDlg,IDC_DESC), szWhole);
  135. }
  136. // if we've travelled through external apprentice pages,
  137. // it's easy for our current page pointer to get munged,
  138. // so reset it here for sanity's sake.
  139. gpWizardState->uCurrentPage = ORD_PAGE_HOWTOCONNECT;
  140. return TRUE;
  141. }
  142. /*******************************************************************
  143. NAME: HowToConnectOKProc
  144. SYNOPSIS: Called when Next or Back btns pressed from "How to
  145. Connect" page
  146. ENTRY: hDlg - dialog window
  147. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  148. puNextPage - if 'Next' was pressed,
  149. proc can fill this in with next page to go to. This
  150. parameter is ingored if 'Back' was pressed.
  151. pfKeepHistory - page will not be kept in history if
  152. proc fills this in with FALSE.
  153. EXIT: returns TRUE to allow page to be turned, FALSE
  154. to keep the same page.
  155. ********************************************************************/
  156. BOOL CALLBACK HowToConnectOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  157. BOOL * pfKeepHistory)
  158. {
  159. ASSERT(puNextPage);
  160. // read radio button state
  161. if( IsDlgButtonChecked(hDlg, IDC_CONNECT_BY_LAN) )
  162. {
  163. gpUserInfo->uiConnectionType = CONNECT_LAN;
  164. }
  165. else if( IsDlgButtonChecked(hDlg, IDC_CONNECT_BY_PHONE) )
  166. {
  167. gpUserInfo->uiConnectionType = CONNECT_RAS;
  168. }
  169. else if( IsDlgButtonChecked(hDlg, IDC_CONNECT_MANUAL) )
  170. {
  171. ASSERT( gpWizardState->dwRunFlags & RSW_APPRENTICE );
  172. gpUserInfo->uiConnectionType = CONNECT_MANUAL;
  173. }
  174. if (!fForward)
  175. {
  176. if ( !(gpWizardState->dwRunFlags & RSW_APPRENTICE) )
  177. {
  178. // Hack to make back work...
  179. gpWizardState->uPagesCompleted = 1;
  180. gfUserBackedOut = TRUE;
  181. gfQuitWizard = TRUE;
  182. }
  183. }
  184. else
  185. {
  186. if ( (gpWizardState->dwRunFlags & RSW_APPRENTICE) && !g_fIsICW)
  187. {
  188. if ( !(CONNECT_RAS == gpUserInfo->uiConnectionType) )
  189. {
  190. // 12/20/96 jmazner Normandy #12945
  191. // don't go through proxy options.
  192. // we're about to jump back to the external wizard, and we don't want
  193. // this page to show up in our history list
  194. *pfKeepHistory = FALSE;
  195. *puNextPage = g_uExternUINext;
  196. //Notify the main Wizard that this was the last page
  197. ASSERT( g_pExternalIICWExtension )
  198. if (g_fIsExternalWizard97)
  199. g_pExternalIICWExtension->SetFirstLastPage(0, IDD_PAGE_HOWTOCONNECT97);
  200. else
  201. g_pExternalIICWExtension->SetFirstLastPage(0, IDD_PAGE_HOWTOCONNECT);
  202. g_fConnectionInfoValid = TRUE;
  203. }
  204. else
  205. {
  206. //
  207. // 12/20/96 jmazner Normandy #12948
  208. // Install a modem if neccesary
  209. //
  210. // 5/15/97 jmazner Olympus
  211. //DWORD dwfInstallOptions = INETCFG_INSTALLMODEM;
  212. DWORD dwfInstallOptions = (INETCFG_INSTALLRNA | INETCFG_INSTALLMODEM | INETCFG_INSTALLTCP);
  213. EnableWindow(GetParent(hDlg), FALSE);
  214. //
  215. // save state of fNeedReboot, becasuse
  216. // we might be calling InetCofigureSystem()
  217. // again, and the ReBoot flag might get reset
  218. // MKarki - Fix for Bug #404
  219. //
  220. BOOL bSaveState = gpWizardState->fNeedReboot;
  221. HRESULT hr = InetConfigSystem(GetParent(hDlg),dwfInstallOptions,&gpWizardState->fNeedReboot);
  222. //
  223. // we should choose to reboot -MKarki Bug #404
  224. //
  225. gpWizardState->fNeedReboot =
  226. bSaveState || gpWizardState->fNeedReboot;
  227. EnableWindow(GetParent(hDlg), TRUE);
  228. SetForegroundWindow(GetParent(hDlg));
  229. if (hr == ERROR_CANCELLED)
  230. {
  231. // Stay on this page if the user cancelled
  232. gpWizardState->fNeedReboot = FALSE;
  233. return FALSE;
  234. }
  235. else if (hr != ERROR_SUCCESS)
  236. {
  237. MsgBox(GetParent(hDlg),IDS_CONFIGAPIFAILED,MB_ICONEXCLAMATION,MB_OK);
  238. gpWizardState->fNeedReboot = FALSE;
  239. gfQuitWizard = TRUE;
  240. return FALSE;
  241. }
  242. else if (gpWizardState->fNeedReboot)
  243. {
  244. //
  245. // 5/27/97 jmazner Olympus #1134 and IE #32717
  246. // As per email from GeorgeH and GeoffR, force user to either
  247. // cancel or quit at this point.
  248. //
  249. if (IDYES == MsgBox(GetParent(hDlg),IDS_WANTTOREBOOT,MB_ICONQUESTION, MB_YESNO | MB_DEFBUTTON2))
  250. {
  251. gpWizardState->fNeedReboot = TRUE;
  252. }
  253. else
  254. {
  255. gpWizardState->fNeedReboot = FALSE;
  256. }
  257. gfQuitWizard = TRUE;
  258. return TRUE;
  259. }
  260. //
  261. // 7/16/97 jmazner Olympus #9571
  262. // if the configSystem call installed a modem for the first time on
  263. // the user's machine, then the TAPI information we initially read
  264. // in was bogus because the user had never filled it in.
  265. // Therefore re initialize the fields to make sure we have accurate info
  266. //
  267. InitRasEntry( gpRasEntry );
  268. *puNextPage = GetModemPage(hDlg);
  269. }
  270. }
  271. else
  272. {
  273. //Normandy# 4575 install TCP/IP on LAN path
  274. //Normandy# 8620 Do not install TCP/IP on LAN path
  275. DWORD dwfInstallOptions = 0;
  276. if (CONNECT_RAS == gpUserInfo->uiConnectionType)
  277. dwfInstallOptions |= (INETCFG_INSTALLRNA | INETCFG_INSTALLMODEM | INETCFG_INSTALLTCP);
  278. else if (CONNECT_LAN == gpUserInfo->uiConnectionType)
  279. dwfInstallOptions |= INETCFG_INSTALLTCP;
  280. //
  281. // Install and configure TCP/IP and RNA
  282. //
  283. //
  284. // save state of fNeedReboot, becasuse
  285. // we might be calling InetCofigureSystem()
  286. // again, and the ReBoot flag might get reset
  287. // MKarki - Fix for Bug #404
  288. //
  289. BOOL bSaveState = gpWizardState->fNeedReboot;
  290. HRESULT hr = InetConfigSystem(GetParent(hDlg),dwfInstallOptions,&gpWizardState->fNeedReboot);
  291. //
  292. // we should choose to reboot -MKarki Bug #404
  293. //
  294. gpWizardState->fNeedReboot =
  295. bSaveState || gpWizardState->fNeedReboot;
  296. SetForegroundWindow(GetParent(hDlg));
  297. if (hr == ERROR_CANCELLED) {
  298. // Stay on this page if the user cancelled
  299. gpWizardState->fNeedReboot = FALSE;
  300. if (g_fIsICW)
  301. {
  302. g_pExternalIICWExtension->ExternalCancel( CANCEL_PROMPT );
  303. }
  304. return FALSE;
  305. } else if (hr != ERROR_SUCCESS) {
  306. MsgBox(GetParent(hDlg),IDS_CONFIGAPIFAILED,MB_ICONEXCLAMATION,MB_OK);
  307. gpWizardState->fNeedReboot = FALSE;
  308. //gfQuitWizard = TRUE;
  309. // 2/27/97 jmazner Olympus #299
  310. // don't quit, give the user a chance to choose LAN
  311. gpUserInfo->uiConnectionType = CONNECT_LAN;
  312. CheckDlgButton(hDlg,IDC_CONNECT_BY_PHONE,FALSE);
  313. CheckDlgButton(hDlg,IDC_CONNECT_BY_LAN,TRUE);
  314. EnableWindow(GetDlgItem(hDlg,IDC_CONNECT_BY_PHONE),FALSE);
  315. return FALSE;
  316. } else if (ERROR_SUCCESS == hr && gpWizardState->fNeedReboot && IsNT()) {
  317. //
  318. // we will let the EXE that called us POP up the dialog
  319. // box, asking users to reboot or not
  320. // MKarki (2/5/97) - Fix for Bug #3111
  321. //
  322. g_bReboot = TRUE;
  323. gfQuitWizard = TRUE;
  324. if (!g_fIsICW)
  325. {
  326. PropSheet_PressButton(GetParent(hDlg),PSBTN_CANCEL);
  327. SetPropSheetResult(hDlg,-1);
  328. }
  329. return (FALSE);
  330. }
  331. g_bRebootAtExit = gpWizardState->fNeedReboot;
  332. //
  333. // 7/16/97 jmazner Olympus #9571
  334. // if the configSystem call installed a modem for the first time on
  335. // the user's machine, then the TAPI information we initially read
  336. // in was bogus because the user had never filled it in.
  337. // Therefore re initialize the fields to make sure we have accurate info
  338. //
  339. InitRasEntry( gpRasEntry );
  340. if (dwfInstallOptions & INETCFG_INSTALLRNA)
  341. {
  342. if (ERROR_SUCCESS != InetStartServices())
  343. {
  344. //
  345. // condition when
  346. // 1) user deliberately removes some file
  347. // 2) Did not reboot after installing RAS
  348. // MKarki - (5/7/97) - Fix for Bug #4004
  349. //
  350. MsgBox(
  351. GetParent(hDlg),
  352. IDS_SERVICEDISABLED,
  353. MB_ICONEXCLAMATION,MB_OK
  354. );
  355. /*********
  356. //
  357. // Bug #12544 - VetriV
  358. // Check if user wants to exit ICW
  359. //
  360. if( (MsgBox(GetParent(hDlg), IDS_QUERYCANCEL,
  361. MB_APPLMODAL | MB_ICONQUESTION
  362. | MB_SETFOREGROUND | MB_DEFBUTTON2,
  363. MB_YESNO) == IDNO))
  364. {
  365. goto StartService;
  366. }
  367. else
  368. {
  369. gpWizardState->fNeedReboot = FALSE;
  370. gfQuitWizard = TRUE;
  371. ****/
  372. // 2/27/97 jmazner Olympus #299
  373. // don't quit, give the user a chance to choose LAN
  374. gpUserInfo->uiConnectionType = CONNECT_LAN;
  375. CheckDlgButton(hDlg,IDC_CONNECT_BY_PHONE,FALSE);
  376. CheckDlgButton(hDlg,IDC_CONNECT_BY_LAN,TRUE);
  377. EnableWindow(GetDlgItem(hDlg,IDC_CONNECT_BY_PHONE),FALSE);
  378. return FALSE;
  379. }
  380. }
  381. // jmazner 11/11/96 Normandy #11320
  382. // Note: we are explicitly deferring the reboot until after the wizard
  383. // has completed.
  384. //if( gpWizardState->fNeedReboot )
  385. //{
  386. // gfQuitWizard = TRUE;
  387. // return TRUE;
  388. //}
  389. if (CONNECT_LAN == gpUserInfo->uiConnectionType)
  390. {
  391. // Skip the use proxy page
  392. *puNextPage = ORD_PAGE_SETUP_PROXY;
  393. }
  394. else
  395. {
  396. // get the next page based on number of modems.
  397. *puNextPage = GetModemPage(hDlg);
  398. }
  399. }
  400. }
  401. return TRUE;
  402. }
  403. /*******************************************************************
  404. NAME: ChooseModemInitProc
  405. SYNOPSIS: Called when "Choose Modem" page is displayed
  406. ENTRY: hDlg - dialog window
  407. fFirstInit - TRUE if this is the first time the dialog
  408. is initialized, FALSE if this InitProc has been called
  409. before (e.g. went past this page and backed up)
  410. ********************************************************************/
  411. BOOL CALLBACK ChooseModemInitProc(HWND hDlg,BOOL fFirstInit)
  412. {
  413. ProcessDBCS(hDlg, IDC_MODEM);
  414. gpWizardState->uCurrentPage = ORD_PAGE_CHOOSEMODEM;
  415. // fill the combobox with available modems
  416. DWORD dwRet = InitModemList(GetDlgItem(hDlg,IDC_MODEM));
  417. if (ERROR_SUCCESS != dwRet)
  418. {
  419. DisplayErrorMessage(hDlg,IDS_ERREnumModem,dwRet,
  420. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  421. // set flag to indicate that wizard should exit now
  422. gfQuitWizard = TRUE;
  423. return FALSE;
  424. }
  425. if (-1 == ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_MODEM), nCurrentModemSel))
  426. ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_MODEM), 0);
  427. return TRUE;
  428. }
  429. /*******************************************************************
  430. NAME: ChooseModemCmdProc
  431. SYNOPSIS: Called when modem selected on page
  432. ENTRY: hDlg - dialog window
  433. ********************************************************************/
  434. BOOL CALLBACK ChooseModemCmdProc(HWND hDlg,WPARAM wParam,LPARAM lParam)
  435. {
  436. return TRUE;
  437. }
  438. /*******************************************************************
  439. NAME: ChooseModemOKProc
  440. SYNOPSIS: Called when Next or Back btns pressed from "Choose Modem"
  441. page
  442. ENTRY: hDlg - dialog window
  443. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  444. puNextPage - if 'Next' was pressed,
  445. proc can fill this in with next page to go to. This
  446. parameter is ingored if 'Back' was pressed.
  447. pfKeepHistory - page will not be kept in history if
  448. proc fills this in with FALSE.
  449. EXIT: returns TRUE to allow page to be turned, FALSE
  450. to keep the same page.
  451. ********************************************************************/
  452. BOOL CALLBACK ChooseModemOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  453. BOOL * pfKeepHistory)
  454. {
  455. if (fForward)
  456. {
  457. // get modem name out of combo box
  458. ComboBox_GetText(GetDlgItem(hDlg,IDC_MODEM),
  459. gpRasEntry->szDeviceName,ARRAYSIZE(gpRasEntry->szDeviceName));
  460. NULL_TERM_TCHARS(gpRasEntry->szDeviceName);
  461. ASSERT(lstrlen(gpRasEntry->szDeviceName));
  462. // set next page to go to
  463. // jmazner 11/11/96 Normandy #8293
  464. //*puNextPage = ORD_PAGE_CONNECTION;
  465. // 10/05/98 Vincent Yung
  466. // Connectoid page is removed.
  467. /*
  468. ENUM_CONNECTOID EnumConnectoid; // class object for enum
  469. // 3/21/97 jmazner Olympus #1948
  470. if( EnumConnectoid.NumEntries() )
  471. {
  472. *puNextPage = ORD_PAGE_CONNECTION;
  473. }
  474. else
  475. {
  476. // 5/8/97 jmazner Olympus #4108
  477. // move connectionName to the end
  478. //*puNextPage = ORD_PAGE_CONNECTIONNAME;
  479. *puNextPage = ORD_PAGE_PHONENUMBER;
  480. }*/
  481. *puNextPage = ORD_PAGE_PHONENUMBER;
  482. }
  483. // Store modem selection
  484. nCurrentModemSel = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_MODEM));
  485. // clear the modem list
  486. ComboBox_ResetContent(GetDlgItem(hDlg,IDC_MODEM));
  487. return TRUE;
  488. }
  489. /*******************************************************************
  490. NAME: EnableWizard
  491. SYNOPSIS: Enables or disables the wizard buttons and the wizard
  492. page itself (so it can't receive focus)
  493. ********************************************************************/
  494. VOID EnableWizard(HWND hDlg,BOOL fEnable)
  495. {
  496. HWND hwndWiz = GetParent(hDlg);
  497. // disable/enable back, next, cancel and help buttons
  498. EnableWindow(GetDlgItem(hwndWiz,IDD_BACK),fEnable);
  499. EnableWindow(GetDlgItem(hwndWiz,IDD_NEXT),fEnable);
  500. EnableWindow(GetDlgItem(hwndWiz,IDCANCEL),fEnable);
  501. EnableWindow(GetDlgItem(hwndWiz,IDHELP),fEnable);
  502. // disable/enable wizard page
  503. EnableWindow(hwndWiz,fEnable);
  504. UpdateWindow(hwndWiz);
  505. }
  506. //*******************************************************************
  507. //
  508. // FUNCTION: GetModemPage
  509. //
  510. // PURPOSE: This is only called from a few places. This same logic
  511. // would have otherwise had to be included several times, this
  512. // centralizes the logic. The possible pages returned are the
  513. // "Need Modem" page, the "Choose Modem" page, and "Has ISP".
  514. //
  515. // PARAMETERS: Parent window.
  516. //
  517. // RETURNS: returns the ordinal of the page to display next after
  518. // initial questions are asked.
  519. //
  520. // HISTORY:
  521. // 96/03/07 markdu Created.
  522. // 96/11/11 jmazner updated to skip new/existing connectoid page
  523. // if no connectoids exist.
  524. //
  525. //*******************************************************************
  526. UINT GetModemPage(HWND hDlg)
  527. {
  528. /*** no reason to handle NT seperately -- jmazner
  529. if (TRUE == IsNT())
  530. {
  531. //TODO: Add call to NT enum modems
  532. return ORD_PAGE_CONNECTION;
  533. }
  534. ***/
  535. // Enumerate the modems
  536. DWORD dwRet = EnumerateModems(hDlg, &gpEnumModem);
  537. if (ERROR_SUCCESS != dwRet)
  538. {
  539. // set flag to indicate that wizard should exit now
  540. gfQuitWizard = TRUE;
  541. return FALSE;
  542. }
  543. if (IsMoreThanOneModemInstalled(gpEnumModem))
  544. {
  545. // Multiple modems installed.
  546. TCHAR szDeviceName[RAS_MaxDeviceName + 1] = TEXT("\0");
  547. TCHAR szDeviceType[RAS_MaxDeviceType + 1] = TEXT("\0"); // modems are installed
  548. // If we want to skip the choose modem dlg.
  549. // retrieve the device info from registry.
  550. if (g_bSkipMultiModem &&
  551. GetDeviceSelectedByUser(DEVICENAMEKEY, szDeviceName, sizeof(szDeviceName)) &&
  552. GetDeviceSelectedByUser(DEVICETYPEKEY, szDeviceType, sizeof(szDeviceType)) )
  553. {
  554. lstrcpy(gpRasEntry->szDeviceName, szDeviceName);
  555. lstrcpy(gpRasEntry->szDeviceType, szDeviceType);
  556. return ORD_PAGE_PHONENUMBER;
  557. }
  558. else
  559. {
  560. return ORD_PAGE_CHOOSEMODEM;
  561. }
  562. }
  563. else
  564. {
  565. // One modem installed.
  566. // Note: this option will also be selected if modems could
  567. // not be enumerated due to an error.
  568. // connecting over modem and all drivers/files are in place, go
  569. // to "existing ISP" page
  570. // return ORD_PAGE_CONNECTION;
  571. ENUM_CONNECTOID EnumConnectoid; // class object for enum
  572. if( EnumConnectoid.NumEntries() )
  573. {
  574. return ORD_PAGE_CONNECTION;
  575. }
  576. else
  577. {
  578. // 5/8/97 jmazner Olympus #4108
  579. // move connectionName to the end
  580. //return ORD_PAGE_CONNECTIONNAME;
  581. return ORD_PAGE_PHONENUMBER;
  582. }
  583. }
  584. }
  585. //*******************************************************************
  586. //
  587. // FUNCTION: EnumerateModems
  588. //
  589. // PURPOSE: This function assumes that RNA is installed,
  590. // then it uses RNA to enumerate the devices.
  591. // If an enum object exists, it is replaced.
  592. //
  593. // PARAMETERS: Pointer to current enum object, if one exists.
  594. // In any case, must be a valid pointer.
  595. // Parent window handle for displaying error message.
  596. //
  597. // RETURNS: HRESULT code (ERROR_SUCCESS if no error occurred).
  598. //
  599. // HISTORY:
  600. // 96/03/07 markdu Created.
  601. //
  602. //*******************************************************************
  603. HRESULT EnumerateModems(HWND hwndParent, ENUM_MODEM** ppEnumModem)
  604. {
  605. DWORD dwRet;
  606. // Should only get here if we want to connect by modem/ISDN
  607. ASSERT(CONNECT_RAS == gpUserInfo->uiConnectionType)
  608. // Load RNA if not already loaded
  609. dwRet = EnsureRNALoaded();
  610. if (ERROR_SUCCESS != dwRet)
  611. {
  612. return dwRet;
  613. }
  614. ENUM_MODEM* pEnumModem = *ppEnumModem;
  615. // Enumerate the modems.
  616. if (pEnumModem)
  617. {
  618. // Re-enumerate the modems to be sure we have the most recent changes
  619. dwRet = pEnumModem->ReInit();
  620. }
  621. else
  622. {
  623. // The object does not exist, so create it.
  624. pEnumModem = new ENUM_MODEM;
  625. if (pEnumModem)
  626. {
  627. dwRet = pEnumModem->GetError();
  628. }
  629. else
  630. {
  631. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  632. }
  633. }
  634. // Check for errors
  635. if (ERROR_SUCCESS != dwRet)
  636. {
  637. DisplayErrorMessage(hwndParent,IDS_ERREnumModem,dwRet,
  638. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  639. // Clean up
  640. if (pEnumModem)
  641. {
  642. delete pEnumModem;
  643. }
  644. pEnumModem = NULL;
  645. }
  646. *ppEnumModem = pEnumModem;
  647. return dwRet;
  648. }
  649. //*******************************************************************
  650. //
  651. // FUNCTION: IsModemInstalled
  652. //
  653. // PURPOSE: This function validates the ENUM_MODEM object, then
  654. // gets the modem count.
  655. //
  656. // PARAMETERS: Modem enum object to use for check.
  657. //
  658. // RETURNS: This function returns TRUE if there is at least one
  659. // modem installed.
  660. //
  661. // HISTORY:
  662. // 96/03/07 markdu Created.
  663. //
  664. //*******************************************************************
  665. BOOL IsModemInstalled(ENUM_MODEM* pEnumModem)
  666. {
  667. if (TRUE == IsNT())
  668. {
  669. BOOL bNeedModem = FALSE;
  670. DWORD dwRet;
  671. if (NULL == lpIcfgNeedModem)
  672. return FALSE;
  673. dwRet = (*lpIcfgNeedModem)(0, &bNeedModem);
  674. if (ERROR_SUCCESS == dwRet)
  675. return !bNeedModem;
  676. else
  677. return FALSE;
  678. }
  679. else
  680. {
  681. if (pEnumModem && pEnumModem->GetNumDevices() > 0)
  682. {
  683. return TRUE;
  684. }
  685. return FALSE;
  686. }
  687. }
  688. //*******************************************************************
  689. //
  690. // FUNCTION: IsMoreThanOneModemInstalled
  691. //
  692. // PURPOSE: This function validates the ENUM_MODEM object, then
  693. // gets the modem count.
  694. //
  695. // PARAMETERS: Modem enum object to use for check.
  696. //
  697. // RETURNS: This function returns TRUE if there is more than one
  698. // modem installed.
  699. //
  700. // HISTORY:
  701. // 96/03/07 markdu Created.
  702. //
  703. //*******************************************************************
  704. BOOL IsMoreThanOneModemInstalled(ENUM_MODEM* pEnumModem)
  705. {
  706. if (IsNT4SP3Lower())
  707. {
  708. // TODO: DO NT thing here
  709. return FALSE;
  710. }
  711. if (pEnumModem && pEnumModem->GetNumDevices() > 1)
  712. {
  713. return TRUE;
  714. }
  715. return FALSE;
  716. }
  717. //+----------------------------------------------------------------------------
  718. //
  719. // Function: FGetSystemShutdownPrivledge
  720. //
  721. // Synopsis: For windows NT the process must explicitly ask for permission
  722. // to reboot the system.
  723. //
  724. // Arguements: none
  725. //
  726. // Return: TRUE - privledges granted
  727. // FALSE - DENIED
  728. //
  729. // History: 8/14/96 ChrisK Created
  730. //
  731. // Note: BUGBUG for Win95 we are going to have to softlink to these
  732. // entry points. Otherwise the app won't even load.
  733. // Also, this code was originally lifted out of MSDN July96
  734. // "Shutting down the system"
  735. //-----------------------------------------------------------------------------
  736. BOOL FGetSystemShutdownPrivledge()
  737. {
  738. HANDLE hToken = NULL;
  739. TOKEN_PRIVILEGES tkp;
  740. BOOL bRC = FALSE;
  741. if (IsNT())
  742. {
  743. //
  744. // Get the current process token handle
  745. // so we can get shutdown privilege.
  746. //
  747. if (!OpenProcessToken(GetCurrentProcess(),
  748. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  749. goto FGetSystemShutdownPrivledgeExit;
  750. //
  751. // Get the LUID for shutdown privilege.
  752. //
  753. ZeroMemory(&tkp,sizeof(tkp));
  754. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
  755. &tkp.Privileges[0].Luid);
  756. tkp.PrivilegeCount = 1; /* one privilege to set */
  757. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  758. //
  759. // Get shutdown privilege for this process.
  760. //
  761. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  762. (PTOKEN_PRIVILEGES) NULL, 0);
  763. if (ERROR_SUCCESS == GetLastError())
  764. bRC = TRUE;
  765. }
  766. else
  767. {
  768. bRC = TRUE;
  769. }
  770. FGetSystemShutdownPrivledgeExit:
  771. if (hToken) CloseHandle(hToken);
  772. return bRC;
  773. }