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.

1522 lines
37 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include "UIHelpers.h"
  4. #include "DataSrc.h"
  5. #include "resource.h"
  6. #include <cominit.h>
  7. #include "WMIHelp.h"
  8. #include <HTMLHelp.h>
  9. #include <prsht.h>
  10. #include "WbemError.h"
  11. #include <util.h>
  12. #ifdef SNAPIN
  13. const TCHAR c_HelpFile[] = _T("newfeat1.hlp");
  14. #else
  15. const TCHAR c_HelpFile[] = _T("WbemCntl.hlp");
  16. #endif
  17. //-------------------------------------------------------------------
  18. bool IsNT(DWORD ver /* = 0 */)
  19. {
  20. OSVERSIONINFO os;
  21. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  22. if(!GetVersionEx(&os))
  23. return FALSE; // should never happen
  24. if(os.dwPlatformId != VER_PLATFORM_WIN32_NT)
  25. {
  26. return false;
  27. }
  28. else if(ver == 0)
  29. {
  30. // any version of NT will do.
  31. return true;
  32. }
  33. else
  34. {
  35. return (os.dwMajorVersion == ver);
  36. }
  37. }
  38. //-------------------------------------------------------------------
  39. CNtSid::CNtSid(SidType st)
  40. {
  41. m_pSid = 0;
  42. m_dwStatus = InternalError;
  43. m_pMachine = 0;
  44. if(st == CURRENT_USER ||st == CURRENT_THREAD)
  45. {
  46. HANDLE hToken;
  47. if(st == CURRENT_USER)
  48. {
  49. if(!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken))
  50. return;
  51. }
  52. else
  53. {
  54. if(!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &hToken))
  55. return;
  56. }
  57. // Get the user sid
  58. // ================
  59. TOKEN_USER tu;
  60. DWORD dwLen = 0;
  61. GetTokenInformation(hToken, TokenUser, &tu, sizeof(tu), &dwLen);
  62. if(dwLen == 0)
  63. {
  64. CloseHandle(hToken);
  65. return;
  66. }
  67. BYTE* pTemp = new BYTE[dwLen];
  68. if (!pTemp)
  69. {
  70. CloseHandle(hToken);
  71. return;
  72. }
  73. DWORD dwRealLen = dwLen;
  74. if(!GetTokenInformation(hToken, TokenUser, pTemp, dwRealLen, &dwLen))
  75. {
  76. CloseHandle(hToken);
  77. delete [] pTemp;
  78. return;
  79. }
  80. CloseHandle(hToken);
  81. // Make a copy of the SID
  82. // ======================
  83. PSID pSid = ((TOKEN_USER*)pTemp)->User.Sid;
  84. DWORD dwSidLen = GetLengthSid(pSid);
  85. m_pSid = new BYTE[dwSidLen];
  86. CopySid(dwSidLen, m_pSid, pSid);
  87. delete [] pTemp;
  88. m_dwStatus = 0;
  89. }
  90. return;
  91. }
  92. //-------------------------------------------------------------------
  93. CNtSid::~CNtSid()
  94. {
  95. if (m_pSid)
  96. delete [] m_pSid;
  97. if (m_pMachine)
  98. delete [] m_pMachine;
  99. }
  100. //-------------------------------------------------------------------
  101. int CNtSid::GetInfo(LPTSTR *pRetAccount, // Account, use operator delete
  102. LPTSTR *pRetDomain, // Domain, use operator delete
  103. DWORD *pdwUse) // See SID_NAME_USE for values
  104. {
  105. if(pRetAccount)
  106. *pRetAccount = 0;
  107. if(pRetDomain)
  108. *pRetDomain = 0;
  109. if(pdwUse)
  110. *pdwUse = 0;
  111. if(!m_pSid || !IsValidSid(m_pSid))
  112. return InvalidSid;
  113. DWORD dwNameLen = 0;
  114. DWORD dwDomainLen = 0;
  115. LPTSTR pUser = 0;
  116. LPTSTR pDomain = 0;
  117. SID_NAME_USE Use;
  118. // Do the first lookup to get the buffer sizes required.
  119. // =====================================================
  120. BOOL bRes = LookupAccountSid(m_pMachine,
  121. m_pSid,
  122. pUser,
  123. &dwNameLen,
  124. pDomain,
  125. &dwDomainLen,
  126. &Use);
  127. DWORD dwLastErr = GetLastError();
  128. if(dwLastErr != ERROR_INSUFFICIENT_BUFFER)
  129. {
  130. return Failed;
  131. }
  132. // Allocate the required buffers and look them up again.
  133. // =====================================================
  134. pUser = new TCHAR[dwNameLen + 1];
  135. pDomain = new TCHAR[dwDomainLen + 1];
  136. bRes = LookupAccountSid(m_pMachine,
  137. m_pSid,
  138. pUser,
  139. &dwNameLen,
  140. pDomain,
  141. &dwDomainLen,
  142. &Use);
  143. if(!bRes)
  144. {
  145. delete[] pUser;
  146. delete[] pDomain;
  147. return Failed;
  148. }
  149. if(pRetAccount)
  150. *pRetAccount = pUser;
  151. else
  152. delete[] pUser;
  153. if(pRetDomain)
  154. *pRetDomain = pDomain;
  155. else
  156. delete[] pDomain;
  157. if(pdwUse)
  158. *pdwUse = Use;
  159. return NoError;
  160. }
  161. //-------------------------------------------------------------------
  162. CUIHelpers::CUIHelpers(DataSource *ds, WbemServiceThread *serviceThread,
  163. bool htmlSupport) :
  164. CBasePage(ds, serviceThread), m_sessionID(0),
  165. m_htmlSupport(htmlSupport), m_ImaWizard(false)
  166. {
  167. }
  168. //-------------------------------------------------------------------
  169. CUIHelpers::CUIHelpers(CWbemServices &service,
  170. bool htmlSupport) :
  171. CBasePage(service), m_sessionID(0), m_htmlSupport(htmlSupport),
  172. m_ImaWizard(false)
  173. {
  174. }
  175. //-------------------------------------------------------------------
  176. CUIHelpers::~CUIHelpers( void )
  177. {
  178. }
  179. //---------------------------------------------------
  180. LPTSTR CUIHelpers::CloneString( LPTSTR pszSrc )
  181. {
  182. LPTSTR pszDst = NULL;
  183. if (pszSrc != NULL)
  184. {
  185. pszDst = new TCHAR[(lstrlen(pszSrc) + 1)];
  186. if (pszDst)
  187. {
  188. lstrcpy( pszDst, pszSrc );
  189. }
  190. }
  191. return pszDst;
  192. }
  193. //--------------------------------------------------------------
  194. void CUIHelpers::SetWbemService(IWbemServices *pServices)
  195. {
  196. g_serviceThread->m_realServices = pServices; //VINOTH
  197. m_WbemServices = pServices;
  198. }
  199. //--------------------------------------------------------------
  200. bool CUIHelpers::ServiceIsReady(UINT uCaption,
  201. UINT uWaitMsg,
  202. UINT uBadMsg)
  203. {
  204. switch(g_serviceThread->m_status)
  205. {
  206. // its already there.
  207. case WbemServiceThread::ready:
  208. {
  209. ATLTRACE(_T("start marshal\n"));
  210. for(int i = 0; (i < 5); i++)
  211. {
  212. // if "Object is not connected to server"
  213. if(g_serviceThread->m_hr == 0x800401fd)
  214. {
  215. // lost my connection,
  216. ATLTRACE(_T("Reconnecting to cimom!!!!!!!!!!!\n"));
  217. g_serviceThread->ReConnect();
  218. ATLTRACE(_T("new service status: %d\n"), g_serviceThread->m_status);
  219. continue;
  220. }
  221. else if(FAILED(g_serviceThread->m_hr))
  222. {
  223. // some other problem.
  224. g_serviceThread->m_status = WbemServiceThread::error;
  225. }
  226. ATLTRACE(_T("marshalled ok\n"));
  227. break; //for
  228. } //endfor
  229. if(m_AVIbox)
  230. {
  231. PostMessage(m_AVIbox,
  232. WM_ASYNC_CIMOM_CONNECTED,
  233. 0, 0);
  234. m_AVIbox = 0;
  235. }
  236. // it marshaled, must still be connected/useable.
  237. return true;
  238. }
  239. break;
  240. // its coming.
  241. case WbemServiceThread::notStarted:
  242. case WbemServiceThread::locating:
  243. case WbemServiceThread::connecting:
  244. {
  245. if(m_alreadyAsked)
  246. {
  247. return false;
  248. }
  249. // let me know when its there.
  250. g_serviceThread->NotifyWhenDone(m_hDlg);
  251. // also kill the cancel box at that time.
  252. m_AVIbox = 0;
  253. g_serviceThread->NotifyWhenDone(m_AVIbox);
  254. m_alreadyAsked = true;
  255. if(uCaption != NO_UI)
  256. {
  257. TCHAR caption[100] ={0}, msg[256] = {0};
  258. ::LoadString(_Module.GetModuleInstance(), uCaption,
  259. caption, 100);
  260. ::LoadString(_Module.GetModuleInstance(), uWaitMsg,
  261. msg, 256);
  262. m_userCancelled = false;
  263. if(DisplayAVIBox(m_hDlg, caption, msg, &m_AVIbox) == IDCANCEL)
  264. {
  265. g_serviceThread->Cancel();
  266. m_userCancelled = true;
  267. }
  268. }
  269. }
  270. return false;
  271. break;
  272. case WbemServiceThread::error: // cant connect.
  273. case WbemServiceThread::threadError: // cant start that thread.
  274. default:
  275. m_AVIbox = 0;
  276. if(uCaption != NO_UI)
  277. {
  278. // DisplayUserMessage(m_hDlg, HINST_THISDLL,
  279. // uCaption, uBadMsg,
  280. // g_serviceThread->m_hr,
  281. // MB_ICONSTOP);
  282. }
  283. return false;
  284. }; //endswitch
  285. return false;
  286. }
  287. //---------------------------------------------------
  288. #define PB_NOTHING_PENDING 0
  289. #define PB_PENDING 1
  290. #define PB_COMMIT 2
  291. // STATIC INITIALIZE
  292. int CUIHelpers::m_needToPut[3] = {PB_NOTHING_PENDING,
  293. PB_NOTHING_PENDING,
  294. PB_NOTHING_PENDING};
  295. void CUIHelpers::PageChanged(int page, bool needToPut)
  296. {
  297. if(needToPut)
  298. {
  299. ::SendMessage(GetParent(m_hDlg), PSM_CHANGED, (WPARAM)m_hDlg, 0L);
  300. m_needToPut[page] = PB_PENDING;
  301. ATLTRACE(_T("%d pending now\n"), page);
  302. }
  303. else
  304. {
  305. m_needToPut[page] = PB_NOTHING_PENDING;
  306. }
  307. }
  308. //---------------------------------------------------
  309. HRESULT CUIHelpers::NeedToPut(int page, BOOL refresh)
  310. {
  311. bool allPagesReady = true;
  312. int x;
  313. HRESULT hr = S_OK;
  314. switch(m_needToPut[page])
  315. {
  316. case PB_NOTHING_PENDING:
  317. case PB_COMMIT:
  318. return S_OK; // unnecessary call.
  319. break;
  320. case PB_PENDING:
  321. m_needToPut[page] = PB_COMMIT; // lets do it.
  322. ATLTRACE(_T("%d committed now\n"), page);
  323. break;
  324. }
  325. // it that the last one?
  326. for(x = 0; x <= PB_LASTPAGE; x++)
  327. {
  328. // somebody hasn't committed yet.
  329. // NOTE: ignoring the PB_NOTHING_PENDING's.
  330. if(m_needToPut[x] == PB_PENDING)
  331. {
  332. // wait awhile longer.
  333. allPagesReady = false;
  334. break;
  335. }
  336. }
  337. if(allPagesReady)
  338. {
  339. hr = m_DS->PutWMISetting(refresh);
  340. if(FAILED(hr))
  341. {
  342. CHString1 caption;
  343. TCHAR errMsg[256] = {0};
  344. caption.LoadString(IDS_SHORT_NAME);
  345. ErrorStringEx(hr, errMsg, 256);
  346. MessageBox(m_hDlg, errMsg, caption, MB_OK|MB_ICONWARNING);
  347. }
  348. ATLTRACE(_T("PUTINSTANCE now\n"));
  349. // clear the flags.
  350. for(x = 0; x <= PB_LASTPAGE; x++)
  351. {
  352. m_needToPut[x] = PB_NOTHING_PENDING;
  353. }
  354. }
  355. ::SendMessage(GetParent(m_hDlg), PSM_UNCHANGED, (WPARAM)m_hDlg, 0L);
  356. return hr;
  357. }
  358. //------------------------------------------------------------------------
  359. bool CUIHelpers::BrowseForFile(HWND hDlg,
  360. UINT idTitle,
  361. LPCTSTR lpstrFilter,
  362. LPCTSTR initialFile,
  363. LPTSTR pathFile,
  364. UINT pathFileSize,
  365. DWORD moreFlags /*= 0*/)
  366. {
  367. bool retval = false;
  368. if(m_DS->IsLocal())
  369. {
  370. OPENFILENAME OpenFileName;
  371. CHString1 title;
  372. title.LoadString(idTitle);
  373. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  374. OpenFileName.hwndOwner = hDlg;
  375. OpenFileName.hInstance = 0;
  376. OpenFileName.lpstrFilter = lpstrFilter;
  377. OpenFileName.lpstrCustomFilter = NULL;
  378. OpenFileName.nMaxCustFilter = 0;
  379. OpenFileName.nFilterIndex = 0;
  380. OpenFileName.lpstrFile = pathFile;
  381. OpenFileName.nMaxFile = pathFileSize;
  382. OpenFileName.lpstrFileTitle = NULL;
  383. OpenFileName.nMaxFileTitle = 0;
  384. OpenFileName.lpstrInitialDir = initialFile;
  385. OpenFileName.lpstrTitle = (LPCTSTR)title;
  386. OpenFileName.nFileOffset = 0;
  387. OpenFileName.nFileExtension = 0;
  388. OpenFileName.lpstrDefExt = _T("rec");
  389. OpenFileName.lCustData = NULL;
  390. OpenFileName.lpfnHook = NULL;
  391. OpenFileName.lpTemplateName = NULL;
  392. #if (_WIN32_WINNT >= 0x0500)
  393. OpenFileName.Flags = OFN_HIDEREADONLY|OFN_DONTADDTORECENT;
  394. #else
  395. OpenFileName.Flags = OFN_HIDEREADONLY;
  396. #endif
  397. //Adding OFN_NOCHANGEDIR here so that the Open File dialog doesn't hold on to the directory - otherwise
  398. //the recovery fails because it needs to rename the dir.
  399. OpenFileName.Flags |= moreFlags | OFN_NOCHANGEDIR;
  400. // Call the common dialog function.
  401. if(GetOpenFileName(&OpenFileName))
  402. {
  403. retval = true;
  404. }
  405. else
  406. {
  407. DWORD x = CommDlgExtendedError();
  408. retval = false;
  409. }
  410. }
  411. else // remote connection
  412. {
  413. retval = (DisplayEditDlg(hDlg, idTitle, IDS_CANT_BROWSE_REMOTELY,
  414. pathFile, pathFileSize) == IDOK);
  415. }
  416. return retval;
  417. }
  418. //---------------------------------------------------------
  419. typedef struct {
  420. LPCTSTR lpCaption;
  421. LPCTSTR lpClientMsg;
  422. UINT uAnim;
  423. HWND *boxHwnd;
  424. BOOL cancelBtn;
  425. } ANIMCONFIG;
  426. INT_PTR CALLBACK AnimDlgProc(HWND hwndDlg,
  427. UINT uMsg,
  428. WPARAM wParam,
  429. LPARAM lParam)
  430. {
  431. BOOL retval = FALSE;
  432. switch(uMsg)
  433. {
  434. case WM_INITDIALOG:
  435. {//BEGIN
  436. //lParam = ANIMCONFIG *
  437. ANIMCONFIG *cfg = (ANIMCONFIG *)lParam;
  438. *(cfg->boxHwnd) = hwndDlg;
  439. ::ShowWindow(hwndDlg, SW_SHOW);
  440. if(cfg->cancelBtn == FALSE)
  441. {
  442. ::ShowWindow(::GetDlgItem(hwndDlg, IDCANCEL), SW_HIDE);
  443. }
  444. // save this pointer for the WM_DESTROY.
  445. SetWindowLongPtr(hwndDlg, DWLP_USER, (LPARAM)cfg->boxHwnd);
  446. HWND hAnim = GetDlgItem(hwndDlg, IDC_ANIMATE);
  447. HWND hMsg = GetDlgItem(hwndDlg, IDC_MSG);
  448. Animate_Open(hAnim, MAKEINTRESOURCE(cfg->uAnim));
  449. SetWindowText(hwndDlg, cfg->lpCaption);
  450. SetWindowText(hMsg, cfg->lpClientMsg);
  451. retval = TRUE;
  452. }//END
  453. break;
  454. case WM_ASYNC_CIMOM_CONNECTED:
  455. // the client has completed 'whatever' and I should
  456. // claim victory and go away now.
  457. EndDialog(hwndDlg, IDOK);
  458. break;
  459. case WM_COMMAND:
  460. // they're only one button.
  461. if(HIWORD(wParam) == BN_CLICKED)
  462. {
  463. // I'm going away now so anybody that has a ptr to my
  464. // hwnd (which I gave out in my WM_INITDIALOG) shouldn't
  465. // use it anymore.
  466. HWND *me = (HWND *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  467. *me = 0;
  468. EndDialog(hwndDlg, IDCANCEL);
  469. }
  470. retval = TRUE; // I processed it.
  471. break;
  472. case WM_DESTROY:
  473. {// BEGIN
  474. // I'm going away now so anybody that has a ptr to my
  475. // hwnd (which I gave out in my WM_INITDIALOG) shouldn't
  476. // use it anymore.
  477. HWND *me = (HWND *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  478. *me = 0;
  479. retval = TRUE; // I processed it.
  480. } //END
  481. break;
  482. default:
  483. retval = FALSE; // I did NOT process this msg.
  484. break;
  485. } //endswitch uMsg
  486. return retval;
  487. }
  488. //---------------------------------------------------------
  489. INT_PTR CUIHelpers::DisplayAVIBox(HWND hWnd,
  490. LPCTSTR lpCaption,
  491. LPCTSTR lpClientMsg,
  492. HWND *boxHwnd,
  493. BOOL cancelBtn)
  494. {
  495. ANIMCONFIG cfg = {lpCaption, lpClientMsg, IDR_AVIWAIT, boxHwnd, cancelBtn};
  496. return DialogBoxParam(_Module.GetModuleInstance(),
  497. MAKEINTRESOURCE(IDD_ANIMATE),
  498. hWnd, AnimDlgProc,
  499. (LPARAM)&cfg);
  500. }
  501. //---------------------------------------------------------
  502. typedef struct {
  503. LPTSTR lpName;
  504. UINT cName;
  505. DataSource *ds;
  506. HTREEITEM hSelectedItem;
  507. } PICK_CFG;
  508. INT_PTR CALLBACK NSPickDlgProc(HWND hwndDlg,
  509. UINT uMsg,
  510. WPARAM wParam,
  511. LPARAM lParam)
  512. {
  513. BOOL retval = FALSE;
  514. switch(uMsg)
  515. {
  516. case WM_INITDIALOG:
  517. { //BEGIN
  518. SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
  519. PICK_CFG *data = (PICK_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  520. HWND hTree = GetDlgItem(hwndDlg, IDC_NSTREE);
  521. data->ds->LoadImageList(hTree);
  522. data->ds->LoadNode(hTree, TVI_ROOT, HIDE_SOME);
  523. } //END
  524. retval = TRUE;
  525. break;
  526. case WM_NOTIFY:
  527. {
  528. PICK_CFG *data = (PICK_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  529. switch(((LPNMHDR)lParam)->code)
  530. {
  531. case TVN_SELCHANGED:
  532. if(((LPNMHDR)lParam)->idFrom == IDC_NSTREE)
  533. {
  534. LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
  535. data->hSelectedItem = pnmtv->itemNew.hItem;
  536. }
  537. break;
  538. case TVN_ITEMEXPANDING:
  539. if(((LPNMHDR)lParam)->idFrom == IDC_NSTREE)
  540. {
  541. // expand the node.
  542. LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
  543. if(pnmtv->action == TVE_EXPAND)
  544. {
  545. HWND hTree = GetDlgItem(hwndDlg, IDC_NSTREE);
  546. data->ds->LoadNode(hTree, pnmtv->itemNew.hItem, HIDE_SOME);
  547. }
  548. }
  549. break;
  550. }
  551. }
  552. retval = TRUE;
  553. break;
  554. case WM_COMMAND:
  555. // they're only one button.
  556. switch(LOWORD(wParam))
  557. {
  558. case IDOK:
  559. {
  560. PICK_CFG *data = (PICK_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  561. // save the currently selected fullpath name.
  562. HWND hTree = ::GetDlgItem(hwndDlg, IDC_NSTREE);
  563. TV_ITEM item;
  564. item.mask = TVIF_PARAM;
  565. item.hItem = data->hSelectedItem;
  566. BOOL x = TreeView_GetItem(hTree, &item);
  567. struct NSNODE *node = ((ITEMEXTRA *)item.lParam)->nsNode;
  568. if(node && data)
  569. _tcsncpy(data->lpName, node->fullPath, data->cName);
  570. EndDialog(hwndDlg, IDOK);
  571. }
  572. break;
  573. case IDCANCEL:
  574. {
  575. EndDialog(hwndDlg, IDCANCEL);
  576. }
  577. break;
  578. default:
  579. return(FALSE);
  580. } // switch
  581. break;
  582. default:
  583. retval = FALSE; // I did NOT process this msg.
  584. break;
  585. } //endswitch uMsg
  586. return retval;
  587. }
  588. //---------------------------------------------------------
  589. INT_PTR CUIHelpers::DisplayNSBrowser(HWND hWnd,
  590. LPTSTR lpName,
  591. UINT cName)
  592. {
  593. PICK_CFG cfg;
  594. cfg.lpName = lpName;
  595. cfg.cName = cName;
  596. cfg.ds = m_DS;
  597. cfg.hSelectedItem = 0;
  598. return DialogBoxParam(_Module.GetModuleInstance(),
  599. MAKEINTRESOURCE(IDD_NS_PICKER),
  600. hWnd, NSPickDlgProc,
  601. (LPARAM)&cfg);
  602. }
  603. //---------------------------------------------------------
  604. typedef struct {
  605. LPCTSTR lpCaption;
  606. LPCTSTR lpMsg;
  607. LPTSTR lpEdit;
  608. UINT cEdit;
  609. } EDIT_CFG;
  610. const static DWORD nsBrowseHelpIDs[] = { // Context Help IDs
  611. IDC_NSTREE, IDH_WMI_CTRL_ADVANCED_CHANGE_NAMESPACE,
  612. 65535, -1,
  613. 0, 0
  614. };
  615. INT_PTR CALLBACK EditDlgProc(HWND hwndDlg,
  616. UINT uMsg,
  617. WPARAM wParam,
  618. LPARAM lParam)
  619. {
  620. BOOL retval = FALSE;
  621. switch(uMsg)
  622. {
  623. case WM_INITDIALOG:
  624. { //BEGIN
  625. SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
  626. EDIT_CFG *data = (EDIT_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  627. if(data->lpMsg)
  628. {
  629. ::SetWindowText(GetDlgItem(hwndDlg, IDC_MSG), data->lpMsg);
  630. }
  631. if(data->lpCaption)
  632. {
  633. SetWindowText(hwndDlg, data->lpCaption);
  634. }
  635. ::SendMessage(GetDlgItem(hwndDlg, IDC_EDIT), EM_LIMITTEXT, data->cEdit-1, 0);
  636. } //END
  637. retval = TRUE;
  638. break;
  639. case WM_COMMAND:
  640. // they're only one button.
  641. switch(LOWORD(wParam))
  642. {
  643. case IDC_EDIT:
  644. if(HIWORD(wParam) == EN_CHANGE)
  645. {
  646. HWND hwnd = GetDlgItem(hwndDlg, IDOK);
  647. int len = GetWindowTextLength((HWND)lParam);
  648. ::EnableWindow(hwnd, (len > 0));
  649. }
  650. break;
  651. case IDOK:
  652. {
  653. EDIT_CFG *data = (EDIT_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  654. if(data->lpEdit)
  655. {
  656. ::GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT),
  657. data->lpEdit, data->cEdit);
  658. }
  659. EndDialog(hwndDlg, IDOK);
  660. }
  661. break;
  662. case IDCANCEL:
  663. {
  664. EndDialog(hwndDlg, IDCANCEL);
  665. }
  666. break;
  667. default:
  668. return(FALSE);
  669. } // switch
  670. break;
  671. case WM_HELP:
  672. if (IsWindowEnabled(hwndDlg))
  673. {
  674. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  675. c_HelpFile,
  676. HELP_WM_HELP,
  677. (ULONG_PTR)nsBrowseHelpIDs);
  678. }
  679. break;
  680. case WM_CONTEXTMENU:
  681. if (IsWindowEnabled(hwndDlg))
  682. {
  683. WinHelp(hwndDlg, c_HelpFile,
  684. HELP_CONTEXTMENU,
  685. (ULONG_PTR)nsBrowseHelpIDs);
  686. }
  687. break;
  688. default:
  689. retval = FALSE; // I did NOT process this msg.
  690. break;
  691. } //endswitch uMsg
  692. return retval;
  693. }
  694. //---------------------------------------------------------
  695. INT_PTR CUIHelpers::DisplayEditDlg(HWND hWnd,
  696. UINT idCaption,
  697. UINT idMsg,
  698. LPTSTR lpEdit,
  699. UINT cEdit)
  700. {
  701. CHString1 caption, msg;
  702. caption.LoadString(idCaption);
  703. msg.LoadString(idMsg);
  704. EDIT_CFG cfg = {(LPCTSTR)caption, (LPCTSTR)msg, lpEdit, cEdit};
  705. return DialogBoxParam(_Module.GetModuleInstance(),
  706. MAKEINTRESOURCE(IDD_EDITBOX),
  707. hWnd, EditDlgProc,
  708. (LPARAM)&cfg);
  709. }
  710. //---------------------------------------------------------
  711. typedef struct {
  712. LOGIN_CREDENTIALS *credentials;
  713. } LOGIN_CFG;
  714. //------------------------------------------------------------------------
  715. void CredentialUserA(LOGIN_CREDENTIALS *credentials, char **user)
  716. {
  717. //Take twice the length because if they are in Unicode, each unicode char can translate to 2 bytes in multi-byte.
  718. UINT finalSize = (credentials->authIdent->DomainLength +
  719. credentials->authIdent->UserLength) * 2 + 2; //one for terminating '0' and one for the '\'
  720. *user = new char[finalSize];
  721. if(*user == NULL)
  722. return;
  723. memset(*user, 0, finalSize * sizeof(char));
  724. if(credentials->authIdent->Flags == SEC_WINNT_AUTH_IDENTITY_ANSI)
  725. {
  726. if(credentials->authIdent->DomainLength > 0)
  727. {
  728. strcpy(*user, (char *)credentials->authIdent->Domain);
  729. strcat(*user, "\\");
  730. strcat(*user, (char *)credentials->authIdent->User);
  731. }
  732. else
  733. {
  734. strcpy(*user, (char *)credentials->authIdent->User);
  735. }
  736. }
  737. else // convert the UNICODE
  738. {
  739. if(credentials->authIdent->DomainLength > 0)
  740. {
  741. char temp[100] = {0};
  742. //Note we allow twice the length, because assuming the length is in # of characters, each wchar
  743. //could potentially result in 2 bytes for the multi-byte character.
  744. wcstombs(*user, credentials->authIdent->Domain,
  745. credentials->authIdent->DomainLength * 2);
  746. strcat(*user, "\\");
  747. wcstombs(temp, credentials->authIdent->User,
  748. credentials->authIdent->UserLength * 2);
  749. strcat(*user, temp);
  750. }
  751. else
  752. {
  753. wcstombs(*user, credentials->authIdent->User,
  754. credentials->authIdent->UserLength * 2);
  755. }
  756. }
  757. }
  758. //------------------------------------------------------------------------
  759. void CredentialUserW(LOGIN_CREDENTIALS *credentials, wchar_t **user)
  760. {
  761. UINT finalSize = credentials->authIdent->DomainLength +
  762. credentials->authIdent->UserLength + 2; //one for terminating '0' and one for the '\'
  763. *user = new wchar_t[finalSize];
  764. if(*user == NULL)
  765. return;
  766. memset(*user, 0, finalSize * sizeof(wchar_t));
  767. if(credentials->authIdent->Flags == SEC_WINNT_AUTH_IDENTITY_ANSI)
  768. {
  769. if(credentials->authIdent->DomainLength > 0)
  770. {
  771. wchar_t temp[100] = {0};
  772. mbstowcs(*user, (const char *)credentials->authIdent->Domain,
  773. credentials->authIdent->DomainLength);
  774. wcscat(*user, L"\\");
  775. mbstowcs(temp, (const char *)credentials->authIdent->User,
  776. credentials->authIdent->UserLength);
  777. wcscat(*user, temp);
  778. }
  779. else
  780. {
  781. mbstowcs(*user, (const char *)credentials->authIdent->User,
  782. credentials->authIdent->UserLength);
  783. }
  784. }
  785. else //
  786. {
  787. if(credentials->authIdent->DomainLength > 0)
  788. {
  789. wcscpy(*user, credentials->authIdent->Domain);
  790. wcscat(*user, L"\\");
  791. wcscat(*user, credentials->authIdent->User);
  792. }
  793. else
  794. {
  795. wcscpy(*user, credentials->authIdent->User);
  796. }
  797. }
  798. }
  799. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  800. void SetCurrentUser(HWND hDlg, bool currUser)
  801. {
  802. Button_SetCheck(GetDlgItem(hDlg, IDC_CHECKCURRENTUSER),
  803. (currUser? BST_CHECKED:BST_UNCHECKED));
  804. BOOL enable = (currUser? FALSE: TRUE);
  805. ::EnableWindow(GetDlgItem(hDlg, IDC_EDITUSERNAME), enable);
  806. ::EnableWindow(GetDlgItem(hDlg, IDC_EDITPASSWORD), enable);
  807. ::EnableWindow(GetDlgItem(hDlg, IDC_USER_LABEL), enable);
  808. ::EnableWindow(GetDlgItem(hDlg, IDC_PW_LABEL), enable);
  809. }
  810. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  811. const static DWORD logonHelpIDs[] = { // Context Help IDs
  812. IDC_CHECKCURRENTUSER, IDH_WMI_CTRL_GENERAL_WMILOGIN_CHECKBOX,
  813. IDC_USER_LABEL, IDH_WMI_CTRL_GENERAL_WMILOGIN_USERNAME,
  814. IDC_EDITUSERNAME, IDH_WMI_CTRL_GENERAL_WMILOGIN_USERNAME,
  815. IDC_PW_LABEL, IDH_WMI_CTRL_GENERAL_WMILOGIN_PASSWORD,
  816. IDC_EDITPASSWORD, IDH_WMI_CTRL_GENERAL_WMILOGIN_PASSWORD,
  817. 0, 0
  818. };
  819. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  820. INT_PTR CALLBACK LoginDlgProc(HWND hwndDlg,
  821. UINT uMsg,
  822. WPARAM wParam,
  823. LPARAM lParam)
  824. {
  825. BOOL retval = FALSE;
  826. switch(uMsg)
  827. {
  828. case WM_INITDIALOG:
  829. { //BEGIN
  830. SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
  831. LOGIN_CFG *data = (LOGIN_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  832. SetCurrentUser(hwndDlg, data->credentials->currUser);
  833. } //END
  834. retval = TRUE;
  835. break;
  836. case WM_COMMAND:
  837. {
  838. LOGIN_CFG *data = (LOGIN_CFG *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  839. switch(LOWORD(wParam))
  840. {
  841. case IDC_CHECKCURRENTUSER:
  842. {
  843. if(HIWORD(wParam) == BN_CLICKED)
  844. {
  845. bool currUser = (IsDlgButtonChecked(hwndDlg, IDC_CHECKCURRENTUSER) == BST_CHECKED ?true:false);
  846. // toggle and respond.
  847. SetCurrentUser(hwndDlg, currUser);
  848. }
  849. }
  850. break;
  851. case IDOK:
  852. {
  853. if(HIWORD(wParam) == BN_CLICKED)
  854. {
  855. data->credentials->currUser = (IsDlgButtonChecked(hwndDlg, IDC_CHECKCURRENTUSER) == BST_CHECKED ?true:false);
  856. if(data->credentials->currUser == false)
  857. {
  858. TCHAR user[100] = {0}, pw[100] = {0};
  859. GetWindowText(GetDlgItem(hwndDlg, IDC_EDITUSERNAME), user, 100);
  860. GetWindowText(GetDlgItem(hwndDlg, IDC_EDITPASSWORD), pw, 100);
  861. BSTR bDomUser, bUser = NULL, bDomain = NULL, bAuth = NULL;
  862. //#ifdef SNAPIN
  863. wchar_t *temp = pw;
  864. bDomUser = SysAllocString(user);
  865. /*#else
  866. wchar_t temp[100] = {0};
  867. mbstowcs(temp, user, 100);
  868. bDomUser = SysAllocString(temp);
  869. mbstowcs(temp, pw, 100);
  870. #endif*/
  871. if(SUCCEEDED(DetermineLoginType(bDomain, bUser, bAuth, bDomUser)))
  872. {
  873. if(data->credentials->authIdent != 0)
  874. {
  875. if(data->credentials->fullAcct)
  876. {
  877. data->credentials->fullAcct[0] = 0;
  878. }
  879. WbemFreeAuthIdentity(data->credentials->authIdent);
  880. data->credentials->authIdent = 0;
  881. }
  882. HRESULT hr = WbemAllocAuthIdentity(bUser, temp, bDomain,
  883. &(data->credentials->authIdent));
  884. _tcscpy(data->credentials->fullAcct, user);
  885. }
  886. }
  887. EndDialog(hwndDlg, IDOK);
  888. }
  889. }
  890. break;
  891. case IDCANCEL:
  892. {
  893. if(HIWORD(wParam) == BN_CLICKED)
  894. {
  895. EndDialog(hwndDlg, IDCANCEL);
  896. }
  897. }
  898. break;
  899. default:
  900. return(FALSE);
  901. } // switch
  902. break;
  903. } // - - - - - - - - endswitch LOWORD()
  904. break;
  905. case WM_HELP:
  906. if(IsWindowEnabled(hwndDlg))
  907. {
  908. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  909. c_HelpFile,
  910. HELP_WM_HELP,
  911. (ULONG_PTR)logonHelpIDs);
  912. }
  913. break;
  914. case WM_CONTEXTMENU:
  915. if(IsWindowEnabled(hwndDlg))
  916. {
  917. WinHelp(hwndDlg, c_HelpFile,
  918. HELP_CONTEXTMENU,
  919. (ULONG_PTR)logonHelpIDs);
  920. }
  921. break;
  922. default: break;
  923. } //endswitch uMsg
  924. return retval;
  925. }
  926. //---------------------------------------------------------
  927. INT_PTR DisplayLoginDlg(HWND hWnd,
  928. LOGIN_CREDENTIALS *credentials)
  929. {
  930. LOGIN_CFG cfg;
  931. cfg.credentials = credentials;
  932. return DialogBoxParam(_Module.GetModuleInstance(),
  933. MAKEINTRESOURCE(IDD_LOGIN),
  934. hWnd, LoginDlgProc,
  935. (LPARAM)&cfg);
  936. }
  937. //---------------------------------------------------------
  938. void SetUserAccount(HWND hwndDlg,
  939. LOGIN_CREDENTIALS *credentials)
  940. {
  941. HWND hwnd = GetDlgItem(hwndDlg, IDC_ACCOUNT);
  942. if(credentials->currUser)
  943. {
  944. CHString1 name;
  945. name.LoadString(IDS_CURRENT_USER);
  946. SetWindowText(hwnd, (LPCTSTR)name);
  947. }
  948. else if(credentials->authIdent != 0 &&
  949. credentials->authIdent->UserLength != 0)
  950. {
  951. LPTSTR temp;
  952. CredentialUser(credentials, &temp);
  953. SetWindowText(hwnd, (LPCTSTR)temp);
  954. }
  955. }
  956. //---------------------------------------------------------
  957. void WarnAboutLocalMachine(HWND hwndDlg)
  958. {
  959. TCHAR caption[50] = {0}, threat[100] = {0};
  960. HWND hwnd = GetDlgItem(hwndDlg, IDC_NAME);
  961. ::LoadString(_Module.GetResourceInstance(),
  962. IDS_SHORT_NAME, caption, 50);
  963. ::LoadString(_Module.GetResourceInstance(),
  964. IDS_USE_RADIO, threat, 100);
  965. MessageBox(hwndDlg, threat, caption,
  966. MB_OK|MB_DEFBUTTON1|MB_ICONEXCLAMATION);
  967. SendMessage(hwnd, EM_SETSEL, 0, -1);
  968. SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)"");
  969. SendMessage(hwnd, EM_SETSEL, -1, 0);
  970. CheckRadioButton(hwndDlg, IDC_LOCAL, IDC_REMOTE, IDC_LOCAL);
  971. hwnd = GetDlgItem(hwndDlg, IDC_LOCAL);
  972. SendMessage(hwndDlg, WM_COMMAND,
  973. MAKEWPARAM(IDC_LOCAL, BN_CLICKED),
  974. (LPARAM)hwnd);
  975. SetFocus(hwnd);
  976. }
  977. //---------------------------------------------------------
  978. bool LocalMachineName(LPCTSTR buf)
  979. {
  980. TCHAR name[64] = {0};
  981. DWORD size = 64;
  982. bool retval = false;
  983. UINT len = _tcslen(buf);
  984. if(GetComputerName(name, &size))
  985. {
  986. if((_tcslen(buf) >= 2) &&
  987. (buf[1] == _T('\\')))
  988. {
  989. // ignore the leading whacks.
  990. retval = (_tcsicmp(&buf[2], name) == 0);
  991. }
  992. else if( ((len == 1) && (buf[0] == _T('.'))) ||
  993. ((len == 3) && (buf[2] == _T('.')))
  994. )
  995. {
  996. retval = true;
  997. }
  998. else
  999. {
  1000. retval = (_tcsicmp(buf, name) == 0);
  1001. }
  1002. }
  1003. return retval;
  1004. }
  1005. //---------------------------------------------------------
  1006. const static DWORD connDlgHelpIDs[] = { // Context Help IDs
  1007. IDC_CONN_FRAME, IDH_WMI_EXE_GENERAL_CHGCOMP_CONNECTTO,
  1008. IDC_LOCAL, IDH_WMI_EXE_GENERAL_CHGCOMP_CONNECTTO,
  1009. IDC_REMOTE, IDH_WMI_EXE_GENERAL_CHGCOMP_CONNECTTO,
  1010. IDC_NAME, IDH_WMI_EXE_GENERAL_CHGCOMP_CONNECTTO,
  1011. IDC_LOGON, IDH_WMI_CTRL_GENERAL_CHANGE_BUTTON,
  1012. 0, 0};
  1013. INT_PTR CALLBACK ConnDlgProc(HWND hwndDlg,
  1014. UINT uMsg,
  1015. WPARAM wParam,
  1016. LPARAM lParam)
  1017. {
  1018. BOOL retval = FALSE;
  1019. switch(uMsg)
  1020. {
  1021. case WM_INITDIALOG:
  1022. { //BEGIN
  1023. CUIHelpers *me = (CUIHelpers *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  1024. CONN_NAME *name = 0;
  1025. if(me == 0)
  1026. {
  1027. me = (CUIHelpers *)lParam;
  1028. SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
  1029. }
  1030. name = (CONN_NAME *)&(me->m_cfg);
  1031. if(me->m_ImaWizard)
  1032. {
  1033. ::PropSheet_SetWizButtons(::GetParent(hwndDlg), PSWIZB_FINISH);
  1034. }
  1035. BOOL local = *(name->local);
  1036. ::EnableWindow(GetDlgItem(hwndDlg, IDC_LOCAL),TRUE);
  1037. ::EnableWindow(GetDlgItem(hwndDlg, IDC_REMOTE),TRUE);
  1038. ::EnableWindow(GetDlgItem(hwndDlg, IDC_NAME), !local);
  1039. CheckRadioButton(hwndDlg, IDC_LOCAL, IDC_REMOTE,
  1040. (local ? IDC_LOCAL : IDC_REMOTE));
  1041. HWND hName = GetDlgItem(hwndDlg, IDC_NAME);
  1042. SendMessage(hName, EM_LIMITTEXT, MAXCOMPUTER_NAME, 0);
  1043. SetWindowText(hName, name->lpName);
  1044. BOOL enableOK = (GetWindowTextLength(hName) != 0);
  1045. ::EnableWindow(GetDlgItem(hwndDlg, IDOK), enableOK);
  1046. // deal with the user account.
  1047. SetUserAccount(hwndDlg, name->credentials);
  1048. if(!local)
  1049. {
  1050. ::SetFocus(GetDlgItem(hwndDlg, IDC_NAME));
  1051. return FALSE;
  1052. }
  1053. } //END
  1054. retval = TRUE;
  1055. break;
  1056. case WM_NOTIFY:
  1057. {
  1058. switch(((NMHDR FAR *) lParam)->code)
  1059. {
  1060. case PSN_WIZFINISH:
  1061. {
  1062. CUIHelpers *me = (CUIHelpers *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  1063. CONN_NAME *name = (CONN_NAME *)&(me->m_cfg);
  1064. *(name->local) = (IsDlgButtonChecked(hwndDlg, IDC_LOCAL) == BST_CHECKED ?true:false);
  1065. if(*(name->local) == false)
  1066. {
  1067. GetWindowText(GetDlgItem(hwndDlg, IDC_NAME), name->lpName, name->cName);
  1068. }
  1069. }
  1070. break;
  1071. default: break;
  1072. }
  1073. }
  1074. break;
  1075. case WM_COMMAND:
  1076. {
  1077. // they're only one button.
  1078. CUIHelpers *me = (CUIHelpers *)GetWindowLongPtr(hwndDlg, DWLP_USER);
  1079. CONN_NAME *name = (CONN_NAME *)&(me->m_cfg);
  1080. switch(LOWORD(wParam))
  1081. {
  1082. case IDC_LOCAL:
  1083. {
  1084. ::EnableWindow(GetDlgItem(hwndDlg, IDC_NAME), FALSE);
  1085. // ::EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON), FALSE);
  1086. BOOL local = (IsDlgButtonChecked(hwndDlg, IDC_LOCAL) == BST_CHECKED);
  1087. int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NAME));
  1088. BOOL enableOK = local || (len != 0);
  1089. ::EnableWindow(GetDlgItem(hwndDlg, IDOK), enableOK);
  1090. }
  1091. break;
  1092. case IDC_REMOTE:
  1093. {
  1094. ::EnableWindow(GetDlgItem(hwndDlg, IDC_NAME), TRUE);
  1095. // ::EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON), TRUE);
  1096. BOOL local = (IsDlgButtonChecked(hwndDlg, IDC_LOCAL) == BST_CHECKED);
  1097. int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NAME));
  1098. BOOL enableOK = local || (len != 0);
  1099. ::EnableWindow(GetDlgItem(hwndDlg, IDOK), enableOK);
  1100. }
  1101. break;
  1102. case IDC_NAME:
  1103. switch(HIWORD(wParam))
  1104. {
  1105. case EN_CHANGE:
  1106. {
  1107. BOOL local = (IsDlgButtonChecked(hwndDlg, IDC_LOCAL) == BST_CHECKED);
  1108. int len = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NAME));
  1109. BOOL enableOK = local || (len != 0);
  1110. if(len)
  1111. {
  1112. TCHAR buf[MAXCOMPUTER_NAME + 1] = {0};
  1113. HWND hwnd = GetDlgItem(hwndDlg, IDC_NAME);
  1114. GetWindowText(hwnd, buf, MAXCOMPUTER_NAME + 1);
  1115. }
  1116. ::EnableWindow(GetDlgItem(hwndDlg, IDOK), enableOK);
  1117. }
  1118. break;
  1119. default: break;
  1120. } //end switch HIWORD(wParam)
  1121. break;
  1122. /*********************
  1123. disabling third party logon
  1124. case IDC_LOGON:
  1125. if(DisplayLoginDlg(hwndDlg, name->credentials) == IDOK)
  1126. {
  1127. HWND hwnd = GetDlgItem(hwndDlg, IDC_ACCOUNT);
  1128. if(name->credentials->currUser)
  1129. {
  1130. CHString1 name;
  1131. name.LoadString(IDS_CURRENT_USER);
  1132. SetWindowText(hwnd, (LPCTSTR)name);
  1133. }
  1134. else if(name->credentials->authIdent->UserLength != 0)
  1135. {
  1136. LPTSTR temp;
  1137. CredentialUser(name->credentials, &temp);
  1138. if(_tcslen(temp) > 0)
  1139. {
  1140. SetWindowText(hwnd, (LPCTSTR)temp);
  1141. }
  1142. }
  1143. } //endif DisplayLoginDlg()
  1144. break;
  1145. *******************/
  1146. case IDOK:
  1147. *(name->local) = (IsDlgButtonChecked(hwndDlg, IDC_LOCAL) == BST_CHECKED ?true:false);
  1148. if(*(name->local) == false)
  1149. {
  1150. HWND hwnd = GetDlgItem(hwndDlg, IDC_NAME);
  1151. GetWindowText(hwnd, name->lpName, name->cName);
  1152. if(LocalMachineName(name->lpName))
  1153. {
  1154. WarnAboutLocalMachine(hwndDlg);
  1155. return TRUE;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. name->credentials->currUser = true;
  1161. WbemFreeAuthIdentity(name->credentials->authIdent);
  1162. name->credentials->authIdent = 0;
  1163. memset(name->credentials->fullAcct, 0, 100 * sizeof(TCHAR));
  1164. }
  1165. EndDialog(hwndDlg, IDOK);
  1166. break;
  1167. case IDCANCEL:
  1168. EndDialog(hwndDlg, IDCANCEL);
  1169. break;
  1170. default:
  1171. return(FALSE);
  1172. } // switch
  1173. }
  1174. break;
  1175. case WM_HELP:
  1176. if(IsWindowEnabled(hwndDlg))
  1177. {
  1178. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  1179. c_HelpFile,
  1180. HELP_WM_HELP,
  1181. (ULONG_PTR)connDlgHelpIDs);
  1182. }
  1183. break;
  1184. case WM_CONTEXTMENU:
  1185. if(IsWindowEnabled(hwndDlg))
  1186. {
  1187. WinHelp(hwndDlg, c_HelpFile,
  1188. HELP_CONTEXTMENU,
  1189. (ULONG_PTR)connDlgHelpIDs);
  1190. }
  1191. break;
  1192. default:
  1193. retval = FALSE; // I did NOT process this msg.
  1194. break;
  1195. } //endswitch uMsg
  1196. return retval;
  1197. }
  1198. //---------------------------------------------------------
  1199. INT_PTR CUIHelpers::DisplayCompBrowser(HWND hWnd,
  1200. LPTSTR lpName,
  1201. UINT cName,
  1202. bool *local,
  1203. LOGIN_CREDENTIALS *credentials)
  1204. {
  1205. CUIHelpers dummy(NULL, NULL, false);
  1206. dummy.m_cfg.lpName = lpName;
  1207. dummy.m_cfg.cName = cName;
  1208. dummy.m_cfg.local = local;
  1209. dummy.m_cfg.credentials = credentials;
  1210. return DialogBoxParam(_Module.GetModuleInstance(),
  1211. MAKEINTRESOURCE(IDD_CONNECT),
  1212. hWnd, ConnDlgProc,
  1213. (LPARAM)&dummy);
  1214. }
  1215. //=======================================================================
  1216. ConnectPage::ConnectPage(DataSource *ds, bool htmlSupport) :
  1217. CUIHelpers(ds, &(ds->m_rootThread), htmlSupport)
  1218. {
  1219. m_isLocal = true;
  1220. m_ImaWizard = true;
  1221. std::auto_ptr<TCHAR> AutoTchar (new TCHAR[256]);
  1222. m_cfg.lpName = AutoTchar.get();
  1223. if( m_cfg.lpName ) {
  1224. memset(m_cfg.lpName, 0, 256 * sizeof(TCHAR));
  1225. m_cfg.cName = 256;
  1226. std::auto_ptr<bool> AutoBool (new bool);
  1227. m_cfg.local = AutoBool.get();
  1228. if(m_cfg.local) {
  1229. *m_cfg.local = m_isLocal;
  1230. }
  1231. AutoBool.release();
  1232. m_cfg.credentials = m_DS->GetCredentials();
  1233. }
  1234. AutoTchar.release();
  1235. }
  1236. //-------------------------------------------------------------------------
  1237. ConnectPage::~ConnectPage(void)
  1238. {
  1239. if(m_cfg.lpName)
  1240. {
  1241. delete m_cfg.lpName;
  1242. }
  1243. }
  1244. //------------------------------------------------------------------------
  1245. BOOL ConnectPage::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1246. {
  1247. BOOL retval = false;
  1248. retval = (BOOL)ConnDlgProc(hDlg, uMsg, wParam, lParam);
  1249. if((uMsg == WM_NOTIFY &&
  1250. ((NMHDR FAR *) lParam)->code == PSN_WIZFINISH))
  1251. {
  1252. if(*m_cfg.local)
  1253. {
  1254. // an empty string will cause a local connection.
  1255. m_cfg.lpName[0] = '\0';
  1256. }
  1257. m_DS->SetMachineName(CHString1(m_cfg.lpName));
  1258. }
  1259. return retval;
  1260. }
  1261. //=======================================================================
  1262. void CUIHelpers::HTMLHelper(HWND hDlg)
  1263. {
  1264. if(m_htmlSupport)
  1265. {
  1266. TCHAR helpDir[_MAX_PATH+100] = {0}; //make room for additions below
  1267. if(GetWindowsDirectory(helpDir, _MAX_PATH+1) != 0)
  1268. {
  1269. _tcscat(helpDir, _T("\\Help"));
  1270. #ifdef SNAPIN
  1271. _tcscat(helpDir, _T("\\newfeat1.chm::wmi_control_overview.htm"));
  1272. #else
  1273. _tcscat(helpDir, _T("\\WbemCntl.chm::wmi_control_overview.htm"));
  1274. #endif
  1275. HWND hwnd = HtmlHelp(NULL, helpDir, HH_DISPLAY_TOPIC, NULL);
  1276. if(hwnd == 0)
  1277. {
  1278. CHString1 caption, threat;
  1279. caption.LoadString(IDS_SHORT_NAME);
  1280. threat.LoadString(IDS_NO_HELP);
  1281. MessageBox(hDlg, threat, caption, MB_OK|MB_ICONWARNING);
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. CHString1 caption, threat;
  1288. caption.LoadString(IDS_SHORT_NAME);
  1289. threat.LoadString(IDS_NO_HHCTRL);
  1290. MessageBox(hDlg, threat, caption, MB_OK|MB_ICONWARNING);
  1291. } //endif m_htmlSupport
  1292. }