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.

559 lines
13 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright (c) 1997-1999 Microsoft Corporation
  4. /**********************************************************************/
  5. #include "precomp.h"
  6. #include "GenPage.h"
  7. #include "LogPage.h"
  8. #include "AdvPage.h"
  9. #include "resource.h"
  10. #include "CHString1.h"
  11. #include "DataSrc.h"
  12. #include "wbemerror.h"
  13. #include "WMIHelp.h"
  14. #include <windowsx.h>
  15. #include <util.h>
  16. #ifdef SNAPIN
  17. const static DWORD genPageHelpIDs[] = { // Context Help IDs
  18. IDC_CHANGE, IDH_WMI_CTRL_GENERAL_CHANGE_BUTTON,
  19. IDC_STATUS, IDH_WMI_CTRL_GENERAL_DISPLAY_INFO,
  20. IDC_GEN_PARA, -1,
  21. 0, 0};
  22. #else
  23. const static DWORD genPageHelpIDs[] = { // Context Help IDs
  24. IDC_COMP_LABEL, IDH_WMI_EXE_GENERAL_CONNECTED_TO,
  25. IDC_MACHINE, IDH_WMI_EXE_GENERAL_CONNECTED_TO,
  26. IDC_CHANGE, IDH_WMI_EXE_GENERAL_CHANGE_BUTTON,
  27. IDC_STATUS, IDH_WMI_CTRL_GENERAL_DISPLAY_INFO,
  28. IDC_GEN_PARA, -1,
  29. 0, 0};
  30. #endif
  31. //-------------------------------------------------------------------------
  32. CGenPage::CGenPage(DataSource *ds, bool htmlSupport) :
  33. CUIHelpers(ds, &(ds->m_rootThread), htmlSupport)
  34. {
  35. m_connected = false;
  36. }
  37. //-------------------------------------------------------------------------
  38. CGenPage::~CGenPage(void)
  39. {
  40. }
  41. //-------------------------------------------------------------------------
  42. /*#undef Static_SetIcon
  43. #define Static_SetIcon(hwndCtl, hIcon) ((HICON)(UINT)(DWORD)::SendMessage((hwndCtl), STM_SETICON, (WPARAM)(HICON)(hIcon), 0L))
  44. */
  45. void CGenPage::StatusIcon(HWND hDlg, UINT icon)
  46. {
  47. HICON hiconT, hIcon = LoadIcon(NULL, MAKEINTRESOURCE(icon));
  48. // set it into the picture control.
  49. if(hIcon)
  50. {
  51. hiconT = Static_SetIcon(GetDlgItem(hDlg, IDC_STATUSICON), hIcon);
  52. // destroy the old icon.
  53. if(hiconT)
  54. {
  55. DestroyIcon(hiconT);
  56. }
  57. }
  58. }
  59. //---------------------------------------------------------------------------
  60. void CGenPage::InitDlg(HWND hDlg)
  61. {
  62. CHString1 local, label;
  63. // SetCHString1ResourceHandle(_Module.GetModuleInstance());
  64. m_hDlg = hDlg;
  65. #ifdef SNAPIN
  66. label.LoadString(IDS_GEN_PARA_SNAPIN);
  67. ::SetWindowText(GetDlgItem(hDlg, IDC_GEN_PARA), label);
  68. #else
  69. local.LoadString(IDS_LOCAL_CONN);
  70. ::SetWindowText(GetDlgItem(hDlg, IDC_MACHINE), local);
  71. #endif
  72. m_DS->SetPropSheetHandle(GetParent(hDlg));
  73. OnConnect(hDlg, m_DS->GetCredentials());
  74. }
  75. //---------------------------------------------------------------------------
  76. void CGenPage::OnConnect(HWND hDlg,
  77. LOGIN_CREDENTIALS *credentials)
  78. {
  79. m_connected = false;
  80. CHString1 wait;
  81. wait.LoadString(IDS_WAIT);
  82. ::SetDlgItemText(hDlg, IDC_STATUS, wait);
  83. //#ifndef SNAPIN
  84. // EnablePrivilege(SE_BACKUP_NAME);
  85. // EnablePrivilege(SE_RESTORE_NAME);
  86. //#endif
  87. HRESULT hr = m_DS->Connect(credentials, m_hDlg);
  88. if(SUCCEEDED(hr))
  89. {
  90. // goto the connecting icon.
  91. StatusIcon(hDlg, IDI_WAITING);
  92. {
  93. TCHAR caption[100] ={0}, msg[256] = {0};
  94. ::LoadString(_Module.GetModuleInstance(), IDS_SHORT_NAME,
  95. caption, 100);
  96. ::LoadString(_Module.GetModuleInstance(), IDS_CONNECTING,
  97. msg, 256);
  98. if(DisplayAVIBox(hDlg, caption, msg, &m_AVIbox) == IDCANCEL)
  99. {
  100. g_serviceThread->Cancel();
  101. }
  102. }
  103. }
  104. else
  105. {
  106. // goto the no-connection icon.
  107. StatusIcon(hDlg, IDI_FAILED);
  108. }
  109. }
  110. //---------------------------------------------------------------------------
  111. void CGenPage::OnFinishConnected(HWND hDlg, LPARAM lParam)
  112. {
  113. if(lParam)
  114. {
  115. IStream *pStream = (IStream *)lParam;
  116. IWbemServices *pServices = 0;
  117. HRESULT hr = CoGetInterfaceAndReleaseStream(pStream,
  118. IID_IWbemServices,
  119. (void**)&pServices);
  120. m_connected = true;
  121. SetWbemService(pServices);
  122. if(ServiceIsReady(NO_UI, 0,0))
  123. {
  124. m_DSStatus = m_DS->Initialize(pServices);
  125. }
  126. HWND hOK = GetDlgItem(GetParent(hDlg), IDOK);
  127. EnableWindow(hOK, TRUE);
  128. }
  129. else
  130. {
  131. HWND hOK = GetDlgItem(GetParent(hDlg), IDOK);
  132. EnableWindow(hOK, FALSE);
  133. }
  134. if(m_AVIbox)
  135. {
  136. PostMessage(m_AVIbox, WM_ASYNC_CIMOM_CONNECTED, 0, 0);
  137. m_AVIbox = 0;
  138. }
  139. }
  140. //---------------------------------------------------------------------------
  141. void CGenPage::MinorError(CHString1 &initMsg, UINT fmtID,
  142. HRESULT hr, CHString1 &success)
  143. {
  144. CHString1 fmt, temp;
  145. fmt.LoadString(fmtID);
  146. if(FAILED(hr))
  147. {
  148. TCHAR errMsg[256] = {0};
  149. ErrorStringEx(hr, errMsg, 256);
  150. temp.Format(fmt, errMsg);
  151. }
  152. else
  153. {
  154. temp.Format(fmt, success);
  155. }
  156. initMsg += temp;
  157. initMsg += "\r\n";
  158. }
  159. //---------------------------------------------------------------------------
  160. void CGenPage::Refresh(HWND hDlg)
  161. {
  162. if(m_DS && m_DS->IsNewConnection(&m_sessionID))
  163. {
  164. CHString1 initMsg;
  165. if(m_DS->m_rootThread.m_status != WbemServiceThread::ready)
  166. {
  167. TCHAR errMsg[256] = {0};
  168. CHString1 fmt, name;
  169. fmt.LoadString(IDS_CONN_FAILED_FMT);
  170. if(FAILED(m_DS->m_rootThread.m_hr))
  171. {
  172. ErrorStringEx(m_DS->m_rootThread.m_hr, errMsg, 256);
  173. }
  174. else if(m_DS->m_rootThread.m_status == WbemServiceThread::notStarted)
  175. {
  176. ::LoadString(_Module.GetModuleInstance(), IDS_STATUS_NOTSTARTED,
  177. errMsg, ARRAYSIZE(errMsg));
  178. }
  179. else if(m_DS->m_rootThread.m_status == WbemServiceThread::cancelled)
  180. {
  181. ::LoadString(_Module.GetModuleInstance(), IDS_STATUS_CANCELLED,
  182. errMsg, ARRAYSIZE(errMsg));
  183. }
  184. if(m_DS->IsLocal())
  185. {
  186. name.LoadString(IDS_LOCAL_CONN);
  187. initMsg.Format(fmt, name, errMsg);
  188. }
  189. else
  190. {
  191. initMsg.Format(fmt, m_DS->m_whackedMachineName, errMsg);
  192. }
  193. // ::SetWindowText(GetDlgItem(hDlg, IDC_MACHINE), _T(""));
  194. m_connected = false;
  195. }
  196. else if(FAILED(m_DSStatus)) // major DS failure.
  197. {
  198. TCHAR errMsg[256] = {0};
  199. CHString1 fmt, name;
  200. fmt.LoadString(IDS_CONN_FAILED_FMT);
  201. ErrorStringEx(m_DSStatus, errMsg, 256);
  202. if(m_DS->IsLocal())
  203. {
  204. name.LoadString(IDS_LOCAL_CONN);
  205. initMsg.Format(fmt, name, errMsg);
  206. }
  207. else
  208. {
  209. initMsg.Format(fmt, m_DS->m_whackedMachineName, errMsg);
  210. }
  211. m_connected = false;
  212. }
  213. else if(FAILED(m_DS->m_settingHr) ||
  214. FAILED(m_DS->m_osHr) ||
  215. FAILED(m_DS->m_cpuHr) ||
  216. FAILED(m_DS->m_securityHr)) // minor DS failures
  217. {
  218. CHString1 success;
  219. success.LoadString(IDS_NO_ERR);
  220. initMsg.LoadString(IDS_PARTIAL_DS_FAILURE);
  221. initMsg += "\r\n\r\n";
  222. // format the details into a coherent msg.
  223. MinorError(initMsg, IDS_CPU_ERR_FMT, m_DS->m_cpuHr, success);
  224. MinorError(initMsg, IDS_SETTING_ERR_FMT, m_DS->m_settingHr, success);
  225. MinorError(initMsg, IDS_SEC_ERR_FMT, m_DS->m_securityHr, success);
  226. MinorError(initMsg, IDS_OS_ERR_FMT, m_DS->m_osHr, success);
  227. m_connected = false;
  228. }
  229. else // it all worked
  230. {
  231. CHString1 temp, label;
  232. CHString1 szNotRemoteable, szUnavailable;
  233. HRESULT hr = S_OK;
  234. BOOL enable = TRUE;
  235. szNotRemoteable.LoadString(IDS_NOT_REMOTEABLE);
  236. szUnavailable.LoadString(IDS_UNAVAILABLE);
  237. // - - - - - - - - - - - - - -
  238. // computer name:
  239. label.LoadString(IDS_CONNECTED_TO_LABEL);
  240. initMsg += label;
  241. if(m_DS->IsLocal())
  242. {
  243. label.LoadString(IDS_LOCAL_CONN);
  244. #ifndef SNAPIN
  245. // ::SetWindowText(GetDlgItem(hDlg, IDC_MACHINE), label);
  246. #endif
  247. initMsg += label;
  248. }
  249. else
  250. {
  251. initMsg += m_DS->m_whackedMachineName;
  252. #ifndef SNAPIN
  253. // SetWindowText(GetDlgItem(hDlg, IDC_MACHINE),
  254. (LPCTSTR)m_DS->m_whackedMachineName);
  255. #endif
  256. }
  257. initMsg += "\r\n\r\n";
  258. #ifdef SNAPIN
  259. LOGIN_CREDENTIALS *credentials = m_DS->GetCredentials();
  260. SetUserName(hDlg, credentials);
  261. #endif
  262. // - - - - - - - - - - - - - -
  263. // operating system:
  264. hr = m_DS->GetCPU(temp);
  265. label.LoadString(IDS_CPU_LABEL);
  266. initMsg += label;
  267. if(SUCCEEDED(hr))
  268. {
  269. initMsg += temp;
  270. }
  271. else //failed
  272. {
  273. initMsg += szUnavailable;
  274. }
  275. initMsg += "\r\n";
  276. // - - - - - - - - - - - - - -
  277. // operating system:
  278. hr = m_DS->GetOS(temp);
  279. label.LoadString(IDS_OS_LABEL);
  280. initMsg += label;
  281. if(SUCCEEDED(hr))
  282. {
  283. initMsg += temp;
  284. }
  285. else //failed
  286. {
  287. initMsg += szUnavailable;
  288. }
  289. initMsg += "\r\n";
  290. // - - - - - - - - - - - - - - -
  291. hr = m_DS->GetOSVersion(temp);
  292. label.LoadString(IDS_OS_VER_LABEL);
  293. initMsg += label;
  294. if(SUCCEEDED(hr))
  295. {
  296. initMsg += temp;
  297. }
  298. else //failed
  299. {
  300. initMsg += szUnavailable;
  301. }
  302. initMsg += "\r\n";
  303. // -------------- Service Pack Number ---------------
  304. hr = m_DS->GetServicePackNumber(temp);
  305. if(SUCCEEDED(hr))
  306. {
  307. label.LoadString(IDS_OS_SERVICE_PACK_LABEL);
  308. initMsg += label;
  309. initMsg += temp;
  310. initMsg += "\r\n";
  311. }
  312. // - - - - - - - - - - - - - -
  313. // wmi build number:
  314. hr = m_DS->GetBldNbr(temp);
  315. label.LoadString(IDS_WMI_VER_LABEL);
  316. initMsg += label;
  317. if(SUCCEEDED(hr))
  318. {
  319. initMsg += temp;
  320. }
  321. else //failed
  322. {
  323. initMsg += szUnavailable;
  324. }
  325. initMsg += "\r\n";
  326. // - - - - - - - - - - - - - -
  327. // wmi install dir:
  328. hr = m_DS->GetInstallDir(temp);
  329. label.LoadString(IDS_WMI_INSTALL_DIR);
  330. initMsg += label;
  331. if(SUCCEEDED(hr))
  332. {
  333. initMsg += temp;
  334. }
  335. else //failed
  336. {
  337. initMsg += szUnavailable;
  338. }
  339. m_connected = true;
  340. } //endif ServiceIsReady()
  341. // - - - - - - - - - - - - - -
  342. SetWindowText(GetDlgItem(hDlg, IDC_STATUS), initMsg);
  343. if(m_DS->IsLocal() == TRUE)
  344. {
  345. EnableWindow(GetDlgItem(hDlg,IDC_CHANGE),FALSE);
  346. }
  347. else
  348. {
  349. EnableWindow(GetDlgItem(hDlg,IDC_CHANGE),TRUE);
  350. }
  351. }
  352. }
  353. //------------------------------------------------------------------------
  354. void CGenPage::SetUserName(HWND hDlg, LOGIN_CREDENTIALS *credentials)
  355. {
  356. // intentionally left blank
  357. }
  358. //------------------------------------------------------------------------
  359. BOOL CGenPage::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  360. {
  361. switch(uMsg)
  362. {
  363. case WM_INITDIALOG:
  364. InitDlg(hDlg);
  365. break;
  366. case WM_ASYNC_CIMOM_CONNECTED:
  367. // if(!m_connected)
  368. {
  369. OnFinishConnected(hDlg, lParam);
  370. Refresh(hDlg); // doesnt get a PSN_SETACTIVE from this.
  371. }
  372. break;
  373. case WM_CIMOM_RECONNECT:
  374. m_DS->Disconnect();
  375. OnConnect(hDlg, m_DS->GetCredentials());
  376. break;
  377. case WM_NOTIFY:
  378. {
  379. switch(((LPNMHDR)lParam)->code)
  380. {
  381. case PSN_SETACTIVE:
  382. Refresh(hDlg);
  383. break;
  384. /********************************
  385. this code essentially blocks us from moving off the first page
  386. when the connection to WMI failed. Removed the block per RAID 509070.
  387. I'm leaving the code in because I'm afraid that something may break.
  388. (It's been well tested - I'm paranoid)
  389. case PSN_KILLACTIVE:
  390. // dont switch away if the connection didn't work.
  391. if(m_connected)
  392. {
  393. ::SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  394. return FALSE;
  395. }
  396. else
  397. {
  398. ::SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  399. return TRUE;
  400. }
  401. break;
  402. ********************************/
  403. case PSN_HELP:
  404. HTMLHelper(hDlg);
  405. break;
  406. }
  407. }
  408. break;
  409. case WM_COMMAND:
  410. switch(LOWORD(wParam))
  411. {
  412. case IDC_CHANGE:
  413. if(HIWORD(wParam) == BN_CLICKED)
  414. {
  415. TCHAR name[MAX_PATH + 1] = {0};
  416. bool isLocal = m_DS->IsLocal();
  417. LOGIN_CREDENTIALS *credentials = m_DS->GetCredentials();
  418. #ifdef SNAPIN
  419. if(DisplayLoginDlg(hDlg, credentials) == IDOK)
  420. {
  421. SetUserName(hDlg, credentials);
  422. // reconnect with new credentials.
  423. m_DS->Disconnect(false);
  424. OnConnect(hDlg, credentials);
  425. } //endif DisplayLoginDlg()
  426. #else
  427. INT_PTR x = DisplayCompBrowser(hDlg, name,
  428. sizeof(name)/sizeof(name[0]),
  429. &isLocal, credentials);
  430. if(x == IDOK)
  431. {
  432. if (m_DS)
  433. m_DS->ClosePropSheet();
  434. if(isLocal)
  435. {
  436. // an empty string will cause a local connection.
  437. name[0] = '\0';
  438. }
  439. m_DS->SetMachineName(CHString1(name));
  440. OnConnect(hDlg, credentials);
  441. }
  442. #endif
  443. } //endif HIWORD
  444. break;
  445. default: break;
  446. } //endswitch
  447. break;
  448. case WM_HELP:
  449. if (IsWindowEnabled(hDlg))
  450. {
  451. //WIERD: for some reaon, I'm getting this msg after closing the
  452. // connect dlg.
  453. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  454. c_HelpFile,
  455. HELP_WM_HELP,
  456. (ULONG_PTR)genPageHelpIDs);
  457. }
  458. break;
  459. case WM_CONTEXTMENU:
  460. if (IsWindowEnabled(hDlg))
  461. {
  462. WinHelp(hDlg, c_HelpFile,
  463. HELP_CONTEXTMENU,
  464. (ULONG_PTR)genPageHelpIDs);
  465. }
  466. break;
  467. default:
  468. return FALSE;
  469. }
  470. return TRUE;
  471. }