Source code of Windows XP (NT5)
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.

2649 lines
84 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: scope.cpp
  7. //
  8. // Contents: implementation of the scope pane
  9. //
  10. // Classes: CScopePane
  11. //
  12. // History: 03-14-1998 stevebl Created
  13. // 05-20-1998 RahulTh added GetUNCPath and modified Command to
  14. // use this function
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "precomp.hxx"
  18. #include <wbemcli.h>
  19. #include "rsoputil.h"
  20. #include <list>
  21. // Comment this line to stop trying to set the main snapin icon in the
  22. // scope pane.
  23. #define SET_SCOPE_ICONS 1
  24. // Un-comment the next line to persist snap-in related data. (This really
  25. // shouldn't be necessary since I get all my info from my parent anyway.)
  26. // #define PERSIST_DATA 1
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // IComponentData implementation
  29. DEBUG_DECLARE_INSTANCE_COUNTER(CScopePane);
  30. CScopePane::CScopePane()
  31. {
  32. #if DBG
  33. dbg_cRef = 0;
  34. #endif
  35. DEBUG_INCREMENT_INSTANCE_COUNTER(CScopePane);
  36. DebugMsg((DM_VERBOSE, TEXT("CScopePane::CScopePane this=%08x ref=%u"), this, dbg_cRef));
  37. m_pToolDefs = NULL;
  38. m_pTracking = NULL;
  39. m_pCatList = NULL;
  40. m_pFileExt = NULL;
  41. m_bIsDirty = FALSE;
  42. m_hwndMainWindow = NULL;
  43. m_fMachine = FALSE;
  44. m_fRSOP = FALSE;
  45. m_iViewState = IDM_WINNER;
  46. m_pScope = NULL;
  47. m_pConsole = NULL;
  48. m_pIClassAdmin = NULL;
  49. m_pIPropertySheetProvider = NULL;
  50. m_fLoaded = FALSE;
  51. m_fExtension = FALSE;
  52. m_pIGPEInformation = NULL;
  53. m_pIRSOPInformation = NULL;
  54. m_dwRSOPFlags = 0;
  55. m_lLastAllocated = 0;
  56. m_ToolDefaults.NPBehavior = NP_PUBLISHED;
  57. m_ToolDefaults.fUseWizard = TRUE;
  58. m_ToolDefaults.fCustomDeployment = FALSE;
  59. m_ToolDefaults.UILevel = INSTALLUILEVEL_FULL;
  60. m_ToolDefaults.szStartPath = L""; // UNDONE - need to come up with a
  61. // good default setting for this
  62. m_ToolDefaults.iDebugLevel = 0;
  63. m_ToolDefaults.fShowPkgDetails = 0;
  64. m_ToolDefaults.nUninstallTrackingMonths = 12;
  65. m_ToolDefaults.fUninstallOnPolicyRemoval = FALSE;
  66. m_ToolDefaults.fZapOn64 = FALSE;
  67. m_ToolDefaults.f32On64 = TRUE;
  68. m_ToolDefaults.fExtensionsOnly = TRUE;
  69. m_CatList.cCategory = 0;
  70. m_CatList.pCategoryInfo = NULL;
  71. m_fBlockAddPackage = FALSE;
  72. m_fDisplayedRsopARPWarning = FALSE;
  73. }
  74. CScopePane::~CScopePane()
  75. {
  76. DEBUG_DECREMENT_INSTANCE_COUNTER(CScopePane);
  77. DebugMsg((DM_VERBOSE, TEXT("CScopePane::~CScopePane this=%08x ref=%u"), this, dbg_cRef));
  78. ClearCategories();
  79. ASSERT(m_pScope == NULL);
  80. ASSERT(CResultPane::lDataObjectRefCount == 0);
  81. }
  82. #include <msi.h>
  83. STDMETHODIMP CScopePane::Initialize(LPUNKNOWN pUnknown)
  84. {
  85. ASSERT(pUnknown != NULL);
  86. HRESULT hr;
  87. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  88. // MMC should only call ::Initialize once!
  89. ASSERT(m_pScope == NULL);
  90. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace,
  91. reinterpret_cast<void**>(&m_pScope));
  92. ASSERT(hr == S_OK);
  93. hr = pUnknown->QueryInterface(IID_IPropertySheetProvider,
  94. (void **)&m_pIPropertySheetProvider);
  95. ASSERT(hr == S_OK);
  96. hr = pUnknown->QueryInterface(IID_IConsole, reinterpret_cast<void**>(&m_pConsole));
  97. ASSERT(hr == S_OK);
  98. #ifdef SET_SCOPE_ICONS
  99. LPIMAGELIST lpScopeImage;
  100. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  101. ASSERT(hr == S_OK);
  102. // Load the bitmaps from the dll
  103. CBitmap bmp16x16;
  104. CBitmap bmp32x32;
  105. bmp16x16.LoadBitmap(IDB_16x16);
  106. bmp32x32.LoadBitmap(IDB_32x32);
  107. // Set the images
  108. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp16x16)),
  109. reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp32x32)),
  110. 0, RGB(255,0,255));
  111. SAFE_RELEASE(lpScopeImage);
  112. #endif
  113. // get the main window
  114. hr = m_pConsole->GetMainWindow(&m_hwndMainWindow);
  115. ASSERT(hr == S_OK);
  116. return S_OK;
  117. }
  118. void CScopePane::RemoveResultPane(CResultPane * pRP)
  119. {
  120. m_sResultPane.erase(pRP);
  121. }
  122. STDMETHODIMP CScopePane::CreateComponent(LPCOMPONENT* ppComponent)
  123. {
  124. ASSERT(ppComponent != NULL);
  125. DebugMsg((DM_VERBOSE, TEXT("CScopePane::CreateComponent this=%08x ppComponent=%08x."), this, ppComponent));
  126. CComObject<CResultPane>* pObject;
  127. CComObject<CResultPane>::CreateInstance(&pObject);
  128. ASSERT(pObject != NULL);
  129. DebugMsg((DM_VERBOSE, TEXT("CScopePane::CreateComponent pObject=%08x."), pObject));
  130. m_sResultPane.insert(pObject);
  131. // Store IComponentData
  132. pObject->SetIComponentData(this);
  133. return pObject->QueryInterface(IID_IComponent,
  134. reinterpret_cast<void**>(ppComponent));
  135. }
  136. HRESULT CScopePane::TestForRSoPData(BOOL * pfPolicyFailed)
  137. {
  138. *pfPolicyFailed = FALSE;
  139. HRESULT hr = S_OK;
  140. IWbemLocator * pLocator = NULL;
  141. IWbemServices * pNamespace = NULL;
  142. IWbemClassObject * pObj = NULL;
  143. IEnumWbemClassObject * pEnum = NULL;
  144. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  145. BSTR strNamespace = SysAllocString(m_szRSOPNamespace);
  146. BSTR strObject = SysAllocString(TEXT("RSOP_ExtensionStatus.extensionGuid=\"{c6dc5466-785a-11d2-84d0-00c04fb169f7}\""));
  147. BSTR strQuery = SysAllocString(TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting"));
  148. ULONG n = 0;
  149. hr = CoCreateInstance(CLSID_WbemLocator,
  150. 0,
  151. CLSCTX_INPROC_SERVER,
  152. IID_IWbemLocator,
  153. (LPVOID *) & pLocator);
  154. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: CoCreateInstance failed with 0x%x"), hr));
  155. if (FAILED(hr))
  156. {
  157. goto cleanup;
  158. }
  159. hr = pLocator->ConnectServer(strNamespace,
  160. NULL,
  161. NULL,
  162. NULL,
  163. 0,
  164. NULL,
  165. NULL,
  166. &pNamespace);
  167. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: pLocator->ConnectServer failed with 0x%x"), hr));
  168. if (FAILED(hr))
  169. {
  170. goto cleanup;
  171. }
  172. hr = pNamespace->ExecQuery(strQueryLanguage,
  173. strQuery,
  174. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  175. NULL,
  176. &pEnum);
  177. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: pNamespace->ExecQuery failed with 0x%x"), hr));
  178. if (FAILED(hr))
  179. {
  180. goto cleanup;
  181. }
  182. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  183. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: pEnum->Next failed with 0x%x"), hr));
  184. if (FAILED(hr))
  185. {
  186. goto cleanup;
  187. }
  188. if (n == 0)
  189. {
  190. // there's no data here
  191. hr = E_FAIL;
  192. goto cleanup;
  193. }
  194. if (pObj)
  195. {
  196. pObj->Release();
  197. pObj=NULL;
  198. }
  199. // check for failed settings
  200. hr = pNamespace->GetObject(strObject,
  201. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  202. NULL,
  203. &pObj,
  204. NULL);
  205. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: pNamespace->GetObject failed with 0x%x"), hr));
  206. if (SUCCEEDED(hr))
  207. {
  208. HRESULT hrStatus;
  209. hr = GetParameter(pObj,
  210. TEXT("error"),
  211. hrStatus);
  212. DebugReportFailure(hr, (DM_WARNING, TEXT("TestForRSoPData: GetParameter(\"error\") failed with 0x%x"), hr));
  213. if (SUCCEEDED(hr))
  214. {
  215. *pfPolicyFailed = hrStatus != 0;
  216. }
  217. }
  218. cleanup:
  219. SysFreeString(strObject);
  220. SysFreeString(strQuery);
  221. SysFreeString(strQueryLanguage);
  222. SysFreeString(strNamespace);
  223. if (pObj)
  224. {
  225. pObj->Release();
  226. }
  227. if (pEnum)
  228. {
  229. pEnum->Release();
  230. }
  231. if (pNamespace)
  232. {
  233. pNamespace->Release();
  234. }
  235. if (pLocator)
  236. {
  237. pLocator->Release();
  238. }
  239. return hr;
  240. }
  241. STDMETHODIMP CScopePane::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  242. {
  243. ASSERT(m_pScope != NULL);
  244. HRESULT hr = S_OK;
  245. // Since it's my folder it has an internal format.
  246. // Design Note: for extension. I can use the fact, that the data object doesn't have
  247. // my internal format and I should look at the node type and see how to extend it.
  248. if (event == MMCN_PROPERTY_CHANGE)
  249. {
  250. SaveToolDefaults();
  251. hr = OnProperties(param);
  252. }
  253. else
  254. {
  255. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  256. MMC_COOKIE cookie = 0;
  257. if (pInternal != NULL)
  258. {
  259. cookie = pInternal->m_cookie;
  260. FREE_INTERNAL(pInternal);
  261. }
  262. else
  263. {
  264. // only way we could not be able to extract our own format is if we're operating as an extension
  265. m_fExtension = TRUE;
  266. }
  267. if (m_fRSOP)
  268. {
  269. if (m_pIRSOPInformation == NULL)
  270. {
  271. WCHAR szBuffer[MAX_DS_PATH];
  272. m_fRSOPEnumerate = FALSE;
  273. IRSOPInformation * pIRSOPInformation;
  274. hr = lpDataObject->QueryInterface(IID_IRSOPInformation,
  275. reinterpret_cast<void**>(&pIRSOPInformation));
  276. if (SUCCEEDED(hr))
  277. {
  278. m_pIRSOPInformation = pIRSOPInformation;
  279. m_pIRSOPInformation->AddRef();
  280. hr = m_pIRSOPInformation->GetFlags(&m_dwRSOPFlags);
  281. if (SUCCEEDED(hr))
  282. {
  283. /* extract the namespace here */
  284. hr = m_pIRSOPInformation->GetNamespace(m_fMachine ? GPO_SECTION_MACHINE : GPO_SECTION_USER, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
  285. if (SUCCEEDED(hr))
  286. {
  287. m_szRSOPNamespace = szBuffer;
  288. // check to be sure that there is data to show in the RSoP database
  289. if SUCCEEDED(TestForRSoPData(&m_fRSOPPolicyFailed))
  290. m_fRSOPEnumerate = TRUE;
  291. }
  292. pIRSOPInformation->Release();
  293. }
  294. }
  295. }
  296. }
  297. else
  298. {
  299. if (m_pIGPEInformation == NULL)
  300. {
  301. IGPEInformation * pIGPEInformation;
  302. hr = lpDataObject->QueryInterface(IID_IGPEInformation,
  303. reinterpret_cast<void**>(&pIGPEInformation));
  304. if (SUCCEEDED(hr))
  305. {
  306. GROUP_POLICY_OBJECT_TYPE gpoType;
  307. hr = pIGPEInformation->GetType(&gpoType);
  308. if (SUCCEEDED(hr))
  309. {
  310. if (gpoType == GPOTypeDS)
  311. {
  312. WCHAR szBuffer[MAX_DS_PATH];
  313. do
  314. {
  315. hr = pIGPEInformation->GetDSPath(GPO_SECTION_ROOT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
  316. if (FAILED(hr))
  317. {
  318. break;
  319. }
  320. m_szGPO = szBuffer;
  321. hr = pIGPEInformation->GetDisplayName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
  322. if (FAILED(hr))
  323. {
  324. break;
  325. }
  326. m_szGPODisplayName = szBuffer;
  327. hr = pIGPEInformation->GetDSPath(m_fMachine ? GPO_SECTION_MACHINE : GPO_SECTION_USER, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
  328. if (FAILED(hr))
  329. {
  330. break;
  331. }
  332. m_pIGPEInformation = pIGPEInformation;
  333. m_pIGPEInformation->AddRef();
  334. m_szLDAP_Path = szBuffer;
  335. hr = pIGPEInformation->GetFileSysPath(m_fMachine ? GPO_SECTION_MACHINE : GPO_SECTION_USER, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
  336. if (FAILED(hr)) break;
  337. m_szGPT_Path = szBuffer;
  338. // Here we get the domain name from the GPT_Path.
  339. // The domain name is the very first element in
  340. // the path so this is quite trivial.
  341. m_szDomainName = &((LPCTSTR)m_szGPT_Path)[2]; // skip the "\\"
  342. m_szDomainName = m_szDomainName.SpanExcluding(L"\\");
  343. m_szGPT_Path += L"\\Applications";
  344. hr = InitializeADE();
  345. LoadToolDefaults();
  346. if (SUCCEEDED(hr))
  347. {
  348. // cleanup archived records in the class store
  349. FILETIME ft;
  350. SYSTEMTIME st;
  351. // get current time
  352. GetSystemTime(&st);
  353. // convert it to a FILETIME value
  354. SystemTimeToFileTime(&st, &ft);
  355. // subtract the right number of days
  356. LARGE_INTEGER li;
  357. li.LowPart = ft.dwLowDateTime;
  358. li.HighPart = ft.dwHighDateTime;
  359. li.QuadPart -= ONE_FILETIME_DAY * (((LONGLONG)m_ToolDefaults.nUninstallTrackingMonths * 365)/12);
  360. ft.dwLowDateTime = li.LowPart;
  361. ft.dwHighDateTime = li.HighPart;
  362. // tell the CS to clean up anything older
  363. m_pIClassAdmin->Cleanup(&ft);
  364. }
  365. else
  366. {
  367. // we can still continue even if
  368. // initialization failed provided
  369. // that the reason it failed is that
  370. // the ClassStore object doesn't exist.
  371. if (CS_E_OBJECT_NOTFOUND == hr)
  372. {
  373. hr = S_OK;
  374. }
  375. else
  376. {
  377. // report error
  378. LogADEEvent(EVENTLOG_ERROR_TYPE, EVENT_ADE_INIT_FAILED, hr);
  379. }
  380. }
  381. } while (0);
  382. }
  383. else
  384. {
  385. // force this to fail
  386. hr = E_FAIL;
  387. }
  388. }
  389. pIGPEInformation->Release();
  390. }
  391. }
  392. }
  393. if (SUCCEEDED(hr))
  394. {
  395. switch(event)
  396. {
  397. case MMCN_EXPAND:
  398. {
  399. hr = OnExpand(cookie, arg, param);
  400. }
  401. break;
  402. case MMCN_SELECT:
  403. hr = OnSelect(cookie, arg, param);
  404. break;
  405. case MMCN_CONTEXTMENU:
  406. hr = OnContextMenu(cookie, arg, param);
  407. break;
  408. case MMCN_REFRESH:
  409. hr = Command(IDM_REFRESH, lpDataObject);
  410. break;
  411. default:
  412. break;
  413. }
  414. }
  415. }
  416. return hr;
  417. }
  418. STDMETHODIMP CScopePane::Destroy()
  419. {
  420. // Delete enumerated scope items
  421. DeleteList();
  422. SAFE_RELEASE(m_pScope);
  423. SAFE_RELEASE(m_pConsole);
  424. SAFE_RELEASE(m_pIClassAdmin);
  425. SAFE_RELEASE(m_pIPropertySheetProvider);
  426. SAFE_RELEASE(m_pIGPEInformation);
  427. SAFE_RELEASE(m_pIRSOPInformation);
  428. return S_OK;
  429. }
  430. STDMETHODIMP CScopePane::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  431. {
  432. ASSERT(ppDataObject != NULL);
  433. CComObject<CDataObject>* pObject;
  434. CComObject<CDataObject>::CreateInstance(&pObject);
  435. ASSERT(pObject != NULL);
  436. pObject->m_fMachine = m_fMachine;
  437. // Save cookie and type for delayed rendering
  438. pObject->SetType(type);
  439. pObject->SetCookie(cookie);
  440. return pObject->QueryInterface(IID_IDataObject,
  441. reinterpret_cast<void**>(ppDataObject));
  442. }
  443. ///////////////////////////////////////////////////////////////////////////////
  444. //// IPersistStreamInit interface members
  445. STDMETHODIMP CScopePane::GetClassID(CLSID *pClassID)
  446. {
  447. ASSERT(pClassID != NULL);
  448. // Copy the CLSID for this snapin
  449. if (m_fRSOP)
  450. {
  451. if (m_fMachine)
  452. *pClassID = CLSID_RSOP_MachineSnapin;
  453. else
  454. *pClassID = CLSID_RSOP_Snapin;
  455. }
  456. else
  457. {
  458. if (m_fMachine)
  459. *pClassID = CLSID_MachineSnapin;
  460. else
  461. *pClassID = CLSID_Snapin;
  462. }
  463. return S_OK;
  464. }
  465. STDMETHODIMP CScopePane::IsDirty()
  466. {
  467. return ThisIsDirty() ? S_OK : S_FALSE;
  468. }
  469. STDMETHODIMP CScopePane::Load(IStream *pStm)
  470. {
  471. #ifdef PERSIST_DATA
  472. ASSERT(pStm);
  473. // Read the string
  474. TCHAR psz[MAX_DS_PATH];
  475. ULONG nBytesRead;
  476. ULONG cb;
  477. HRESULT hr = pStm->Read(&cb, sizeof(ULONG), &nBytesRead);
  478. if (SUCCEEDED(hr))
  479. {
  480. hr = pStm->Read(psz, cb, &nBytesRead);
  481. if (SUCCEEDED(hr))
  482. {
  483. if (cb > MAX_DS_PATH * sizeof(TCHAR))
  484. {
  485. return E_FAIL;
  486. }
  487. m_szLDAP_Path = psz;
  488. hr = pStm->Read(&cb, sizeof(ULONG), &nBytesRead);
  489. if (SUCCEEDED(hr))
  490. {
  491. if (cb > MAX_DS_PATH * sizeof(TCHAR))
  492. {
  493. return E_FAIL;
  494. }
  495. hr = pStm->Read(psz, cb, &nBytesRead);
  496. if (SUCCEEDED(hr))
  497. {
  498. m_szGPT_Path = psz;
  499. m_fLoaded = TRUE;
  500. ClearDirty();
  501. LoadToolDefaults();
  502. }
  503. }
  504. }
  505. }
  506. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  507. #else
  508. return S_OK;
  509. #endif
  510. }
  511. STDMETHODIMP CScopePane::Save(IStream *pStm, BOOL fClearDirty)
  512. {
  513. #ifdef PERSIST_DATA
  514. ASSERT(pStm);
  515. // Write the string
  516. ULONG nBytesWritten;
  517. ULONG cb = (m_szLDAP_Path.GetLength() + 1) * sizeof(TCHAR);
  518. HRESULT hr = pStm->Write(&cb, sizeof(ULONG), &nBytesWritten);
  519. if (FAILED(hr))
  520. return STG_E_CANTSAVE;
  521. hr = pStm->Write(m_szLDAP_Path, cb, &nBytesWritten);
  522. if (FAILED(hr))
  523. return STG_E_CANTSAVE;
  524. cb = (m_szGPT_Path.GetLength() + 1) * sizeof(TCHAR);
  525. hr = pStm->Write(&cb, sizeof(ULONG), &nBytesWritten);
  526. if (FAILED(hr))
  527. return STG_E_CANTSAVE;
  528. hr = pStm->Write(m_szGPT_Path, cb, &nBytesWritten);
  529. if (FAILED(hr))
  530. return STG_E_CANTSAVE;
  531. #endif
  532. if (fClearDirty)
  533. ClearDirty();
  534. return S_OK;
  535. }
  536. STDMETHODIMP CScopePane::GetSizeMax(ULARGE_INTEGER *pcbSize)
  537. {
  538. #ifdef PERSIST_DATA
  539. ASSERT(pcbSize);
  540. ULONG cb = (m_szLDAP_Path.GetLength() + m_szGPT_Path.GetLength() + 2) * sizeof(TCHAR) + 2 * sizeof(ULONG);
  541. // Set the size of the string to be saved
  542. #else
  543. ULONG cb = 0;
  544. #endif
  545. ULISet32(*pcbSize, cb);
  546. return S_OK;
  547. }
  548. STDMETHODIMP CScopePane::InitNew(void)
  549. {
  550. return S_OK;
  551. }
  552. void CScopePane::LoadToolDefaults()
  553. {
  554. CString szFileName = m_szGPT_Path;
  555. szFileName += L"\\";
  556. szFileName += CFGFILE;
  557. FILE * f = _wfopen(szFileName, L"rt");
  558. if (f)
  559. {
  560. WCHAR sz[256];
  561. CString szData;
  562. CString szKey;
  563. while (fgetws(sz, 256, f))
  564. {
  565. szData = sz;
  566. szKey = szData.SpanExcluding(L"=");
  567. szData = szData.Mid(szKey.GetLength()+1);
  568. szData.TrimRight();
  569. szData.TrimLeft();
  570. szKey.TrimRight();
  571. if (0 == szKey.CompareNoCase(KEY_NPBehavior))
  572. {
  573. swscanf(szData, L"%i", &m_ToolDefaults.NPBehavior);
  574. }
  575. else if (0 == szKey.CompareNoCase(KEY_fUseWizard))
  576. {
  577. swscanf(szData, L"%i", &m_ToolDefaults.fUseWizard);
  578. }
  579. else if (0 == szKey.CompareNoCase(KEY_fCustomDeployment))
  580. {
  581. swscanf(szData, L"%i", &m_ToolDefaults.fCustomDeployment);
  582. }
  583. else if (0 == szKey.CompareNoCase(KEY_UILevel))
  584. {
  585. swscanf(szData, L"%i", &m_ToolDefaults.UILevel);
  586. }
  587. else if (0 == szKey.CompareNoCase(KEY_szStartPath))
  588. {
  589. m_ToolDefaults.szStartPath = szData;
  590. }
  591. else if (0 == szKey.CompareNoCase(KEY_nUninstallTrackingMonths))
  592. {
  593. swscanf(szData, L"%i", &m_ToolDefaults.nUninstallTrackingMonths);
  594. }
  595. else if (0 == szKey.CompareNoCase(KEY_iDebugLevel))
  596. {
  597. swscanf(szData, L"%i", &m_ToolDefaults.iDebugLevel);
  598. }
  599. else if (0 == szKey.CompareNoCase(KEY_fShowPkgDetails))
  600. {
  601. swscanf(szData, L"%i", &m_ToolDefaults.fShowPkgDetails);
  602. }
  603. else if (0 == szKey.CompareNoCase(KEY_fUninstallOnPolicyRemoval))
  604. {
  605. swscanf(szData, L"%i", &m_ToolDefaults.fUninstallOnPolicyRemoval);
  606. }
  607. else if (0 == szKey.CompareNoCase(KEY_f32On64))
  608. {
  609. swscanf(szData, L"%i", &m_ToolDefaults.f32On64);
  610. }
  611. else if (0 == szKey.CompareNoCase(KEY_fZapOn64))
  612. {
  613. swscanf(szData, L"%i", &m_ToolDefaults.fZapOn64);
  614. }
  615. else if (0 == szKey.CompareNoCase(KEY_fExtensionsOnly))
  616. {
  617. swscanf(szData, L"%i", &m_ToolDefaults.fExtensionsOnly);
  618. }
  619. }
  620. fclose(f);
  621. }
  622. }
  623. void CScopePane::SaveToolDefaults()
  624. {
  625. CString szFileName = m_szGPT_Path;
  626. szFileName += L"\\";
  627. szFileName += CFGFILE;
  628. FILE * f = _wfopen(szFileName, L"wt");
  629. if (f)
  630. {
  631. fwprintf(f, L"%s=%i\n", KEY_NPBehavior, m_ToolDefaults.NPBehavior);
  632. fwprintf(f, L"%s=%i\n", KEY_fUseWizard, m_ToolDefaults.fUseWizard);
  633. fwprintf(f, L"%s=%i\n", KEY_fCustomDeployment, m_ToolDefaults.fCustomDeployment);
  634. fwprintf(f, L"%s=%i\n", KEY_UILevel, m_ToolDefaults.UILevel);
  635. fwprintf(f, L"%s=%s\n", KEY_szStartPath, m_ToolDefaults.szStartPath);
  636. fwprintf(f, L"%s=%i\n", KEY_nUninstallTrackingMonths, m_ToolDefaults.nUninstallTrackingMonths);
  637. fwprintf(f, L"%s=%i\n", KEY_fUninstallOnPolicyRemoval, m_ToolDefaults.fUninstallOnPolicyRemoval);
  638. fwprintf(f, L"%s=%i\n", KEY_f32On64, m_ToolDefaults.f32On64);
  639. fwprintf(f, L"%s=%i\n", KEY_fZapOn64, m_ToolDefaults.fZapOn64);
  640. fwprintf(f, L"%s=%i\n", KEY_fExtensionsOnly, m_ToolDefaults.fExtensionsOnly);
  641. if (m_ToolDefaults.iDebugLevel > 0)
  642. {
  643. fwprintf(f, L"%s=%i\n", KEY_iDebugLevel, m_ToolDefaults.iDebugLevel);
  644. }
  645. if (m_ToolDefaults.fShowPkgDetails > 0)
  646. {
  647. fwprintf(f, L"%s=%i\n", KEY_fShowPkgDetails, m_ToolDefaults.fShowPkgDetails);
  648. }
  649. fclose(f);
  650. }
  651. }
  652. //+--------------------------------------------------------------------------
  653. //
  654. // Member: CScopePane::GetClassStoreName
  655. //
  656. // Synopsis: Gets the name of the class store from the DS.
  657. // If the name isn't stored under the "defaultClassStore"
  658. // property then the name "CN = Class Store" is used and the
  659. // property is set.
  660. //
  661. // Arguments: [sz] - [out] name of the class store
  662. // [fCreateOK] - [in] TRUE if the class store is to be created
  663. // if it doesn't already exist. Otherwise this
  664. // routine fails if the class store isn't found.
  665. //
  666. // Returns: S_OK on success
  667. //
  668. // History: 2-17-1998 stevebl Created
  669. //
  670. // Notes: Assumes m_szLDAP_Path contains the path to the DS object.
  671. //
  672. //---------------------------------------------------------------------------
  673. HRESULT CScopePane::GetClassStoreName(CString &sz, BOOL fCreateOK)
  674. {
  675. if (m_fRSOP)
  676. {
  677. return E_UNEXPECTED;
  678. }
  679. HRESULT hr;
  680. LPOLESTR szCSPath;
  681. hr = CsGetClassStorePath((LPOLESTR)((LPCOLESTR)m_szLDAP_Path), &szCSPath);
  682. if (SUCCEEDED(hr))
  683. {
  684. sz = szCSPath;
  685. OLESAFE_DELETE(szCSPath);
  686. }
  687. else
  688. {
  689. if (fCreateOK)
  690. {
  691. // set sz to the default setting and save the path
  692. IADsPathname * pADsPathname = NULL;
  693. hr = CoCreateInstance(CLSID_Pathname,
  694. NULL,
  695. CLSCTX_INPROC_SERVER,
  696. IID_IADsPathname,
  697. (LPVOID*)&pADsPathname);
  698. if (FAILED(hr))
  699. {
  700. return hr;
  701. }
  702. hr = pADsPathname->Set((LPOLESTR)((LPCOLESTR)m_szLDAP_Path), ADS_SETTYPE_FULL);
  703. if (FAILED(hr))
  704. {
  705. pADsPathname->Release();
  706. return hr;
  707. }
  708. hr = pADsPathname->AddLeafElement(L"CN=Class Store");
  709. if (FAILED(hr))
  710. {
  711. pADsPathname->Release();
  712. return hr;
  713. }
  714. BSTR bstr;
  715. hr = pADsPathname->Retrieve(ADS_FORMAT_X500_NO_SERVER, &bstr);
  716. pADsPathname->Release();
  717. if (FAILED(hr))
  718. {
  719. return hr;
  720. }
  721. sz = bstr;
  722. SysFreeString(bstr);
  723. // This has to be here becuase CsSetClassStorePath will fail if the
  724. // class store doesn't already exist.
  725. hr = CsCreateClassStore((LPOLESTR)((LPCOLESTR)sz));
  726. if (FAILED(hr))
  727. {
  728. // Changed to CS_E_OBJECT_ALREADY_EXISTS.
  729. // I check for both ERROR_ALREAD_EXISTS and CS_E_OBJECT_ALREADY_EXISTS
  730. // just to be safe.
  731. if ((hr != HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) && (hr != CS_E_OBJECT_ALREADY_EXISTS))
  732. {
  733. return hr;
  734. }
  735. }
  736. }
  737. }
  738. return hr;
  739. }
  740. //+--------------------------------------------------------------------------
  741. //
  742. // Member: CScopePane::GetPackageDSPath
  743. //
  744. // Synopsis: gets the path to an individual package's DS object
  745. //
  746. // Arguments: [szPath] - [out] LDAP path to the package
  747. // [szPackageName] - [in] name of the package
  748. //
  749. // Returns: S_OK on success
  750. //
  751. // History: 3-26-1998 stevebl Created
  752. //
  753. //---------------------------------------------------------------------------
  754. HRESULT CScopePane::GetPackageDSPath(CString &szPath, LPOLESTR szPackageName)
  755. {
  756. #if 1
  757. LPOLESTR sz;
  758. HRESULT hr = m_pIClassAdmin->GetDNFromPackageName(szPackageName, &sz);
  759. if (FAILED(hr))
  760. {
  761. return hr;
  762. }
  763. szPath = sz;
  764. OLESAFE_DELETE(sz);
  765. #else
  766. HRESULT hr = GetClassStoreName(szPath, FALSE);
  767. if (FAILED(hr))
  768. {
  769. return hr;
  770. }
  771. // set sz to the default setting and save the path
  772. IADsPathname * pADsPathname = NULL;
  773. hr = CoCreateInstance(CLSID_Pathname,
  774. NULL,
  775. CLSCTX_INPROC_SERVER,
  776. IID_IADsPathname,
  777. (LPVOID*)&pADsPathname);
  778. if (FAILED(hr))
  779. {
  780. return hr;
  781. }
  782. hr = pADsPathname->Set((LPOLESTR)((LPCOLESTR)szPath), ADS_SETTYPE_FULL);
  783. if (FAILED(hr))
  784. {
  785. pADsPathname->Release();
  786. return hr;
  787. }
  788. hr = pADsPathname->AddLeafElement(L"CN=Packages");
  789. if (FAILED(hr))
  790. {
  791. pADsPathname->Release();
  792. return hr;
  793. }
  794. CString sz = L"CN=";
  795. sz+= szPackageName;
  796. hr = pADsPathname->AddLeafElement((LPOLESTR)((LPCOLESTR)sz));
  797. if (FAILED(hr))
  798. {
  799. pADsPathname->Release();
  800. return hr;
  801. }
  802. BSTR bstr;
  803. hr = pADsPathname->Retrieve(ADS_FORMAT_X500_NO_SERVER, &bstr);
  804. pADsPathname->Release();
  805. if (FAILED(hr))
  806. {
  807. return hr;
  808. }
  809. szPath = bstr;
  810. SysFreeString(bstr);
  811. #endif
  812. return S_OK;
  813. }
  814. //+--------------------------------------------------------------------------
  815. //
  816. // Member: CScopePane::GetClassStore
  817. //
  818. // Synopsis: gets the IClassAdmin interface and creates a class store if
  819. // it doesn't already exist.
  820. //
  821. // Arguments: [fCreateOK] - TRUE if the Class Store should be created if
  822. // it doesn't already exist.
  823. //
  824. // Returns:
  825. //
  826. // Modifies: m_pIClassAdmin
  827. //
  828. // Derivation:
  829. //
  830. // History: 2-11-1998 stevebl Created
  831. //
  832. // Notes: Assumes m_szLDAP_Path contains the path to the DS object
  833. //
  834. //---------------------------------------------------------------------------
  835. HRESULT CScopePane::GetClassStore(BOOL fCreateOK)
  836. {
  837. HRESULT hr;
  838. CString szCSPath;
  839. hr = GetClassStoreName(szCSPath, fCreateOK);
  840. if (FAILED(hr))
  841. {
  842. return hr;
  843. }
  844. hr = CsGetClassStore((LPOLESTR)((LPCOLESTR)szCSPath), (LPVOID*)&m_pIClassAdmin);
  845. if (FAILED(hr) && fCreateOK)
  846. {
  847. // Sometimes we can get into this wierd state where
  848. // GetClassStoreName was able to create a entry for the class store
  849. // name but it wasn't able to actually create the class store. This
  850. // should handle that special case.
  851. // Try and create it here and then bind to it again.
  852. hr = CsCreateClassStore((LPOLESTR)((LPCOLESTR)szCSPath));
  853. if (FAILED(hr))
  854. {
  855. // Changed to CS_E_OBJECT_ALREADY_EXISTS.
  856. // I check for both ERROR_ALREAD_EXISTS and CS_E_OBJECT_ALREADY_EXISTS
  857. // just to be safe.
  858. // I'll check for both just to be safe.
  859. if ((hr != HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) && (hr != CS_E_OBJECT_ALREADY_EXISTS))
  860. {
  861. return hr;
  862. }
  863. }
  864. hr = CsGetClassStore((LPOLESTR)((LPCOLESTR)szCSPath), (LPVOID*)&m_pIClassAdmin);
  865. }
  866. return hr;
  867. }
  868. UINT CScopePane::CreateNestedDirectory (LPTSTR lpDirectory, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
  869. {
  870. TCHAR szDirectory[MAX_PATH];
  871. LPTSTR lpEnd;
  872. //
  873. // Check for NULL pointer
  874. //
  875. if (!lpDirectory || !(*lpDirectory)) {
  876. SetLastError(ERROR_INVALID_DATA);
  877. return 0;
  878. }
  879. //
  880. // First, see if we can create the directory without having
  881. // to build parent directories.
  882. //
  883. if (CreateDirectory (lpDirectory, lpSecurityAttributes)) {
  884. return 1;
  885. }
  886. //
  887. // If this directory exists already, this is OK too.
  888. //
  889. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  890. return ERROR_ALREADY_EXISTS;
  891. }
  892. //
  893. // No luck, copy the string to a buffer we can munge
  894. //
  895. lstrcpy (szDirectory, lpDirectory);
  896. //
  897. // Find the first subdirectory name
  898. //
  899. lpEnd = szDirectory;
  900. if (szDirectory[1] == TEXT(':')) {
  901. lpEnd += 3;
  902. } else if (szDirectory[1] == TEXT('\\')) {
  903. //
  904. // Skip the first two slashes
  905. //
  906. lpEnd += 2;
  907. //
  908. // Find the slash between the server name and
  909. // the share name.
  910. //
  911. while (*lpEnd && *lpEnd != TEXT('\\')) {
  912. lpEnd++;
  913. }
  914. if (!(*lpEnd)) {
  915. return 0;
  916. }
  917. //
  918. // Skip the slash, and find the slash between
  919. // the share name and the directory name.
  920. //
  921. lpEnd++;
  922. while (*lpEnd && *lpEnd != TEXT('\\')) {
  923. lpEnd++;
  924. }
  925. if (!(*lpEnd)) {
  926. return 0;
  927. }
  928. //
  929. // Leave pointer at the beginning of the directory.
  930. //
  931. lpEnd++;
  932. } else if (szDirectory[0] == TEXT('\\')) {
  933. lpEnd++;
  934. }
  935. while (*lpEnd) {
  936. while (*lpEnd && *lpEnd != TEXT('\\')) {
  937. lpEnd++;
  938. }
  939. if (*lpEnd == TEXT('\\')) {
  940. *lpEnd = TEXT('\0');
  941. if (!CreateDirectory (szDirectory, NULL)) {
  942. if (GetLastError() != ERROR_ALREADY_EXISTS) {
  943. return 0;
  944. }
  945. }
  946. *lpEnd = TEXT('\\');
  947. lpEnd++;
  948. }
  949. }
  950. //
  951. // Create the final directory
  952. //
  953. if (CreateDirectory (szDirectory, lpSecurityAttributes)) {
  954. return 1;
  955. }
  956. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  957. return ERROR_ALREADY_EXISTS;
  958. }
  959. //
  960. // Failed
  961. //
  962. return 0;
  963. }
  964. ///////////////////////////////////////////////////////////////////////////////
  965. //// Notify handlers for IComponentData
  966. HRESULT CScopePane::OnAdd(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  967. {
  968. return E_UNEXPECTED;
  969. }
  970. HRESULT CScopePane::OnExpand(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  971. {
  972. if (arg == TRUE)
  973. {
  974. // Did Initialize get called?
  975. ASSERT(m_pScope != NULL);
  976. EnumerateScopePane(cookie,
  977. param);
  978. }
  979. return S_OK;
  980. }
  981. HRESULT CScopePane::OnSelect(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  982. {
  983. return E_UNEXPECTED;
  984. }
  985. HRESULT CScopePane::OnContextMenu(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  986. {
  987. return S_OK;
  988. }
  989. HRESULT CScopePane::OnProperties(LPARAM param)
  990. {
  991. if (param == NULL)
  992. {
  993. return S_OK;
  994. }
  995. ASSERT(param != NULL);
  996. return S_OK;
  997. }
  998. void CScopePane::EnumerateScopePane(MMC_COOKIE cookie, HSCOPEITEM pParent)
  999. {
  1000. if (m_fRSOP && !m_fRSOPEnumerate)
  1001. {
  1002. // don't allow an empty RSOP database to enumerate the snapin
  1003. return;
  1004. }
  1005. // make sure that the result pane gets enumerated once
  1006. // so that internal structures get initialized.
  1007. // We only have one folder so this is really easy.
  1008. if (cookie != NULL)
  1009. return ;
  1010. if (m_fExtension)
  1011. {
  1012. // if we're an extension then add a root folder to hang everything off of
  1013. SCOPEDATAITEM * m_pScopeItem = new SCOPEDATAITEM;
  1014. memset(m_pScopeItem, 0, sizeof(SCOPEDATAITEM));
  1015. m_pScopeItem->mask = SDI_STR | SDI_PARAM | SDI_CHILDREN;
  1016. #ifdef SET_SCOPE_ICONS
  1017. m_pScopeItem->mask |= SDI_IMAGE | SDI_OPENIMAGE;
  1018. if (m_fRSOP && m_fRSOPPolicyFailed)
  1019. {
  1020. m_pScopeItem->nImage = IMG_CLOSED_FAILED;
  1021. m_pScopeItem->nOpenImage = IMG_OPEN_FAILED;
  1022. }
  1023. else
  1024. {
  1025. m_pScopeItem->nImage = IMG_CLOSEDBOX;
  1026. m_pScopeItem->nOpenImage = IMG_OPENBOX;
  1027. }
  1028. #endif
  1029. m_pScopeItem->relativeID = pParent;
  1030. m_pScopeItem->displayname = (unsigned short *)-1;
  1031. m_pScopeItem->lParam = -1; // made up cookie for my main folder
  1032. m_pScope->InsertItem(m_pScopeItem);
  1033. }
  1034. if (m_pIClassAdmin)
  1035. {
  1036. // if there's no IClassAdmin then there's nothing to enumerate
  1037. set <CResultPane *>::iterator i;
  1038. for (i = m_sResultPane.begin(); i != m_sResultPane.end(); i++)
  1039. {
  1040. (*i)->EnumerateResultPane(cookie);
  1041. }
  1042. }
  1043. }
  1044. STDMETHODIMP CScopePane::GetSnapinDescription(LPOLESTR * lpDescription)
  1045. {
  1046. OLESAFE_COPYSTRING(*lpDescription, L"description");
  1047. return S_OK;
  1048. }
  1049. STDMETHODIMP CScopePane::GetProvider(LPOLESTR * lpName)
  1050. {
  1051. OLESAFE_COPYSTRING(*lpName, L"provider");
  1052. return S_OK;
  1053. }
  1054. STDMETHODIMP CScopePane::GetSnapinVersion(LPOLESTR * lpVersion)
  1055. {
  1056. OLESAFE_COPYSTRING(*lpVersion, L"version");
  1057. return S_OK;
  1058. }
  1059. STDMETHODIMP CScopePane::GetSnapinImage(HICON * hAppIcon)
  1060. {
  1061. return E_NOTIMPL;
  1062. }
  1063. STDMETHODIMP CScopePane::GetStaticFolderImage(HBITMAP * hSmallImage,
  1064. HBITMAP * hSmallImageOpen,
  1065. HBITMAP * hLargeImage,
  1066. COLORREF * cMask)
  1067. {
  1068. return E_NOTIMPL;
  1069. }
  1070. STDMETHODIMP CScopePane::GetHelpTopic(LPOLESTR *lpCompiledHelpFile)
  1071. {
  1072. LPOLESTR lpHelpFile;
  1073. lpHelpFile = (LPOLESTR) CoTaskMemAlloc (MAX_PATH * sizeof(WCHAR));
  1074. if (!lpHelpFile)
  1075. {
  1076. DebugMsg((DM_WARNING, TEXT("CScopePane::GetHelpTopic: Failed to allocate memory.")));
  1077. return E_OUTOFMEMORY;
  1078. }
  1079. if (m_fRSOP)
  1080. {
  1081. ExpandEnvironmentStringsW (L"%SystemRoot%\\Help\\RSOP.chm::/RSPintro.htm",
  1082. lpHelpFile, MAX_PATH);
  1083. }
  1084. else
  1085. {
  1086. ExpandEnvironmentStringsW (L"%SystemRoot%\\Help\\SPConcepts.chm::/ADE.htm",
  1087. lpHelpFile, MAX_PATH);
  1088. }
  1089. *lpCompiledHelpFile = lpHelpFile;
  1090. return S_OK;
  1091. }
  1092. void CScopePane::DeleteList()
  1093. {
  1094. return;
  1095. }
  1096. STDMETHODIMP CScopePane::GetDisplayInfo(SCOPEDATAITEM* pScopeDataItem)
  1097. {
  1098. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1099. ASSERT(pScopeDataItem != NULL);
  1100. if (pScopeDataItem == NULL)
  1101. return E_POINTER;
  1102. if (pScopeDataItem->lParam == -1)
  1103. {
  1104. m_szFolderTitle.LoadString(IDS_FOLDER_TITLE);
  1105. pScopeDataItem->displayname = (unsigned short *)((LPCOLESTR)m_szFolderTitle);
  1106. }
  1107. else
  1108. {
  1109. ASSERT(pScopeDataItem->mask == TVIF_TEXT);
  1110. pScopeDataItem->displayname = (unsigned short *)((LPCOLESTR)m_AppData[pScopeDataItem->lParam].m_pDetails->pszPackageName);
  1111. }
  1112. ASSERT(pScopeDataItem->displayname != NULL);
  1113. return S_OK;
  1114. }
  1115. STDMETHODIMP CScopePane::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  1116. {
  1117. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  1118. return E_POINTER;
  1119. // Make sure both data object are mine
  1120. INTERNAL* pA;
  1121. INTERNAL* pB;
  1122. HRESULT hr = S_FALSE;
  1123. pA = ExtractInternalFormat(lpDataObjectA);
  1124. pB = ExtractInternalFormat(lpDataObjectB);
  1125. if (pA != NULL && pB != NULL)
  1126. hr = ((pA->m_type == pB->m_type) && (pA->m_cookie == pB->m_cookie)) ? S_OK : S_FALSE;
  1127. FREE_INTERNAL(pA);
  1128. FREE_INTERNAL(pB);
  1129. return hr;
  1130. }
  1131. // Scope item property pages:
  1132. STDMETHODIMP CScopePane::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  1133. LONG_PTR handle,
  1134. LPDATAOBJECT lpIDataObject)
  1135. {
  1136. HRESULT hr;
  1137. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1138. INTERNAL* pInternal = ExtractInternalFormat(lpIDataObject);
  1139. if (!pInternal)
  1140. {
  1141. return E_UNEXPECTED;
  1142. }
  1143. MMC_COOKIE cookie = pInternal->m_cookie;
  1144. FREE_INTERNAL(pInternal);
  1145. //
  1146. // make sure we have an up-to-date categories list
  1147. //
  1148. ClearCategories();
  1149. if (m_fRSOP)
  1150. {
  1151. GetRSoPCategories();
  1152. }
  1153. else
  1154. {
  1155. hr = CsGetAppCategories(&m_CatList);
  1156. if (FAILED(hr))
  1157. {
  1158. // report it
  1159. LogADEEvent(EVENTLOG_ERROR_TYPE, EVENT_ADE_GETCATEGORIES_ERROR, hr, NULL);
  1160. // Since failure only means the categories list will be
  1161. // empty, we'll proceed as if nothing happened.
  1162. hr = S_OK;
  1163. }
  1164. }
  1165. //
  1166. // Create the ToolDefs property page
  1167. //
  1168. m_pToolDefs = new CToolDefs();
  1169. m_pToolDefs->m_ppThis = &m_pToolDefs;
  1170. m_pToolDefs->m_pToolDefaults = & m_ToolDefaults;
  1171. m_pToolDefs->m_cookie = cookie;
  1172. m_pToolDefs->m_hConsoleHandle = handle;
  1173. m_pToolDefs->m_fMachine = m_fMachine;
  1174. hr = SetPropPageToDeleteOnClose(&m_pToolDefs->m_psp);
  1175. if (SUCCEEDED(hr))
  1176. {
  1177. HPROPSHEETPAGE hToolDefs = CreateThemedPropertySheetPage(&m_pToolDefs->m_psp);
  1178. if (hToolDefs == NULL)
  1179. return E_UNEXPECTED;
  1180. lpProvider->AddPage(hToolDefs);
  1181. }
  1182. //
  1183. // Create the ToolAdvDefs property page
  1184. //
  1185. m_pToolAdvDefs = new CToolAdvDefs();
  1186. m_pToolAdvDefs->m_ppThis = &m_pToolAdvDefs;
  1187. m_pToolAdvDefs->m_pToolDefaults = & m_ToolDefaults;
  1188. m_pToolAdvDefs->m_cookie = cookie;
  1189. m_pToolAdvDefs->m_hConsoleHandle = handle;
  1190. m_pToolAdvDefs->m_fMachine = m_fMachine;
  1191. hr = SetPropPageToDeleteOnClose(&m_pToolAdvDefs->m_psp);
  1192. if (SUCCEEDED(hr))
  1193. {
  1194. HPROPSHEETPAGE hToolAdvDefs = CreateThemedPropertySheetPage(&m_pToolAdvDefs->m_psp);
  1195. if (hToolAdvDefs == NULL)
  1196. return E_UNEXPECTED;
  1197. lpProvider->AddPage(hToolAdvDefs);
  1198. }
  1199. CString szCSPath;
  1200. hr = GetClassStoreName(szCSPath, FALSE);
  1201. if (SUCCEEDED(hr) && m_pIClassAdmin)
  1202. {
  1203. //
  1204. // Create the FileExt property page
  1205. //
  1206. m_pFileExt = new CFileExt();
  1207. m_pFileExt->m_ppThis = &m_pFileExt;
  1208. m_pFileExt->m_pScopePane = this;
  1209. // no longer need to marshal this, just set it
  1210. m_pFileExt->m_pIClassAdmin = m_pIClassAdmin;
  1211. m_pIClassAdmin->AddRef();
  1212. hr = SetPropPageToDeleteOnClose(&m_pFileExt->m_psp);
  1213. if (SUCCEEDED(hr))
  1214. {
  1215. HPROPSHEETPAGE hFileExt = CreateThemedPropertySheetPage(&m_pFileExt->m_psp);
  1216. if (hFileExt == NULL)
  1217. return E_UNEXPECTED;
  1218. lpProvider->AddPage(hFileExt);
  1219. }
  1220. }
  1221. else
  1222. {
  1223. //
  1224. // Create the FileExt property page without an IClassAdmin
  1225. //
  1226. m_pFileExt = new CFileExt();
  1227. m_pFileExt->m_ppThis = &m_pFileExt;
  1228. m_pFileExt->m_pScopePane = this;
  1229. hr = SetPropPageToDeleteOnClose(&m_pFileExt->m_psp);
  1230. if (SUCCEEDED(hr))
  1231. {
  1232. HPROPSHEETPAGE hFileExt = CreateThemedPropertySheetPage(&m_pFileExt->m_psp);
  1233. if (hFileExt == NULL)
  1234. return E_UNEXPECTED;
  1235. lpProvider->AddPage(hFileExt);
  1236. }
  1237. }
  1238. //
  1239. // Create the CatList property page
  1240. //
  1241. m_pCatList = new CCatList();
  1242. m_pCatList->m_szDomainName = m_szDomainName;
  1243. m_pCatList->m_ppThis = &m_pCatList;
  1244. m_pCatList->m_pScopePane = this;
  1245. m_pCatList->m_fRSOP = m_fRSOP;
  1246. hr = SetPropPageToDeleteOnClose(&m_pCatList->m_psp);
  1247. if (SUCCEEDED(hr))
  1248. {
  1249. HPROPSHEETPAGE hCatList = CreateThemedPropertySheetPage(&m_pCatList->m_psp);
  1250. if (hCatList == NULL)
  1251. return E_UNEXPECTED;
  1252. lpProvider->AddPage(hCatList);
  1253. }
  1254. #ifdef DIGITAL_SIGNATURES
  1255. //
  1256. // Create the Digital Signatures property page
  1257. //
  1258. m_pSignatures = new CSignatures();
  1259. m_pSignatures->m_ppThis = &m_pSignatures;
  1260. m_pSignatures->m_pScopePane = this;
  1261. m_pSignatures->m_fRSOP = m_fRSOP;
  1262. m_pSignatures->m_pIGPEInformation = m_pIGPEInformation;
  1263. hr = SetPropPageToDeleteOnClose(&m_pSignatures->m_psp);
  1264. if (SUCCEEDED(hr))
  1265. {
  1266. HPROPSHEETPAGE hSignatures = CreateThemedPropertySheetPage(&m_pSignatures->m_psp);
  1267. if (hSignatures == NULL)
  1268. return E_UNEXPECTED;
  1269. lpProvider->AddPage(hSignatures);
  1270. }
  1271. #endif // DIGITAL_SIGNATURES
  1272. return S_OK;
  1273. }
  1274. // Scope item property pages:
  1275. STDMETHODIMP CScopePane::QueryPagesFor(LPDATAOBJECT lpDataObject)
  1276. {
  1277. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1278. // Look at the data object and see if it an item that we want to have a property sheet
  1279. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1280. if (pInternal)
  1281. {
  1282. // The main Software Installation node only has a property sheet if
  1283. // we are not in RSOP mode.
  1284. if ((m_fRSOP != TRUE) && (CCT_SCOPE == pInternal->m_type))
  1285. {
  1286. FREE_INTERNAL(pInternal);
  1287. return S_OK;
  1288. }
  1289. FREE_INTERNAL(pInternal);
  1290. }
  1291. return S_FALSE;
  1292. }
  1293. BOOL CScopePane::IsScopePaneNode(LPDATAOBJECT lpDataObject)
  1294. {
  1295. BOOL bResult = FALSE;
  1296. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1297. if (pInternal)
  1298. {
  1299. if (pInternal->m_type == CCT_SCOPE)
  1300. bResult = TRUE;
  1301. FREE_INTERNAL(pInternal);
  1302. }
  1303. return bResult;
  1304. }
  1305. ///////////////////////////////////////////////////////////////////////////////
  1306. // IExtendContextMenu implementation
  1307. //
  1308. STDMETHODIMP CScopePane::AddMenuItems(LPDATAOBJECT pDataObject,
  1309. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1310. LONG * pInsertionAllowed)
  1311. {
  1312. HRESULT hr = S_OK;
  1313. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  1314. if (!pInternal)
  1315. {
  1316. return E_UNEXPECTED;
  1317. }
  1318. CONTEXTMENUITEM menuitem;
  1319. WCHAR szName[256];
  1320. WCHAR szStatus[256];
  1321. menuitem.strName = szName;
  1322. menuitem.strStatusBarText = szStatus;
  1323. menuitem.fFlags = 0;
  1324. menuitem.fSpecialFlags = 0;
  1325. do {
  1326. if ((m_fRSOP != TRUE) && ((*pInsertionAllowed) & CCM_INSERTIONALLOWED_NEW))
  1327. {
  1328. //
  1329. // Add Application menu item
  1330. //
  1331. ::LoadString(ghInstance, IDM_ADD_APP, szName, 256);
  1332. ::LoadString(ghInstance, IDS_ADD_APP_DESC, szStatus, 256);
  1333. menuitem.lCommandID = IDM_ADD_APP;
  1334. menuitem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  1335. hr = pContextMenuCallback->AddItem(&menuitem);
  1336. if (FAILED(hr))
  1337. break;
  1338. }
  1339. if ((m_fRSOP == TRUE) && ((*pInsertionAllowed) & CCM_INSERTIONALLOWED_VIEW))
  1340. {
  1341. menuitem.lCommandID = 0;
  1342. menuitem.fFlags = MFT_SEPARATOR;
  1343. menuitem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  1344. menuitem.fSpecialFlags = CCM_SPECIAL_SEPARATOR;
  1345. hr = pContextMenuCallback->AddItem(&menuitem);
  1346. if (FAILED(hr))
  1347. break;
  1348. ::LoadString(ghInstance, IDM_WINNER, szName, 256);
  1349. ::LoadString(ghInstance, IDS_WINNER_DESC, szStatus, 256);
  1350. menuitem.lCommandID = IDM_WINNER;
  1351. menuitem.fFlags = menuitem.lCommandID == m_iViewState ? MFS_CHECKED | MFT_RADIOCHECK : 0;
  1352. menuitem.fSpecialFlags = 0;
  1353. hr = pContextMenuCallback->AddItem(&menuitem);
  1354. if (FAILED(hr))
  1355. break;
  1356. if ((m_dwRSOPFlags & RSOP_INFO_FLAG_DIAGNOSTIC_MODE) == RSOP_INFO_FLAG_DIAGNOSTIC_MODE)
  1357. {
  1358. // removed packages should only apply when I'm in diagnostic mode
  1359. ::LoadString(ghInstance, IDM_REMOVED, szName, 256);
  1360. ::LoadString(ghInstance, IDS_REMOVED_DESC, szStatus, 256);
  1361. menuitem.lCommandID = IDM_REMOVED;
  1362. menuitem.fFlags = menuitem.lCommandID == m_iViewState ? MFS_CHECKED | MFT_RADIOCHECK : 0;
  1363. hr = pContextMenuCallback->AddItem(&menuitem);
  1364. if (FAILED(hr))
  1365. break;
  1366. }
  1367. if (!m_fMachine)
  1368. {
  1369. ::LoadString(ghInstance, IDM_ARP, szName, 256);
  1370. ::LoadString(ghInstance, IDS_ARP_DESC, szStatus, 256);
  1371. menuitem.lCommandID = IDM_ARP;
  1372. menuitem.fFlags = menuitem.lCommandID == m_iViewState ? MFS_CHECKED | MFT_RADIOCHECK : 0;
  1373. hr = pContextMenuCallback->AddItem(&menuitem);
  1374. if (FAILED(hr))
  1375. break;
  1376. }
  1377. }
  1378. //
  1379. // Update & Remove application if this is a result pane item
  1380. //
  1381. if (pInternal->m_type == CCT_RESULT)
  1382. {
  1383. CAppData & data = m_AppData[pInternal->m_cookie];
  1384. DWORD dwFlags = data.m_pDetails->pInstallInfo->dwActFlags;
  1385. if ((m_fRSOP != TRUE) && ((*pInsertionAllowed) & CCM_INSERTIONALLOWED_TOP))
  1386. {
  1387. ::LoadString(ghInstance, IDM_AUTOINST, szName, 256);
  1388. ::LoadString(ghInstance, IDS_AUTOINST_DESC, szStatus, 256);
  1389. menuitem.lCommandID = IDM_AUTOINST;
  1390. menuitem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  1391. // only enable for published apps
  1392. if (dwFlags & ACTFLG_Published)
  1393. menuitem.fFlags = 0;
  1394. else
  1395. menuitem.fFlags = MFS_DISABLED;
  1396. if (dwFlags & ACTFLG_OnDemandInstall)
  1397. menuitem.fFlags += MFS_CHECKED;
  1398. hr = pContextMenuCallback->AddItem(&menuitem);
  1399. if (FAILED(hr))
  1400. break;
  1401. ::LoadString(ghInstance, IDM_ASSIGN, szName, 256);
  1402. ::LoadString(ghInstance, IDS_ASSIGN_DESC, szStatus, 256);
  1403. menuitem.lCommandID = IDM_ASSIGN;
  1404. if ((dwFlags & ACTFLG_Assigned) || (data.m_pDetails->pInstallInfo->PathType == SetupNamePath))
  1405. menuitem.fFlags = MFS_DISABLED;
  1406. else
  1407. menuitem.fFlags = 0;
  1408. hr = pContextMenuCallback->AddItem(&menuitem);
  1409. if (FAILED(hr))
  1410. break;
  1411. ::LoadString(ghInstance, IDM_PUBLISH, szName, 256);
  1412. ::LoadString(ghInstance, IDS_PUBLISH_DESC, szStatus, 256);
  1413. menuitem.lCommandID = IDM_PUBLISH;
  1414. if ((dwFlags & ACTFLG_Published) || m_fMachine)
  1415. menuitem.fFlags = MFS_DISABLED;
  1416. else
  1417. menuitem.fFlags = 0;
  1418. hr = pContextMenuCallback->AddItem(&menuitem);
  1419. if (FAILED(hr))
  1420. break;
  1421. #if 0
  1422. ::LoadString(ghInstance, IDM_DISABLE, szName, 256);
  1423. ::LoadString(ghInstance, IDS_DISABLE_DESC, szStatus, 256);
  1424. if (dwFlags & (ACTFLG_Published | ACTFLG_Assigned))
  1425. menuitem.fFlags = 0;
  1426. else
  1427. menuitem.fFlags = MFS_DISABLED;
  1428. menuitem.lCommandID = IDM_DISABLE;
  1429. hr = pContextMenuCallback->AddItem(&menuitem);
  1430. if (FAILED(hr))
  1431. break;
  1432. #endif
  1433. menuitem.lCommandID = 0;
  1434. menuitem.fFlags = MFT_SEPARATOR;
  1435. menuitem.fSpecialFlags = CCM_SPECIAL_SEPARATOR;
  1436. hr = pContextMenuCallback->AddItem(&menuitem);
  1437. if (FAILED(hr))
  1438. break;
  1439. }
  1440. if ((m_fRSOP != TRUE) && ((*pInsertionAllowed) & CCM_INSERTIONALLOWED_TASK))
  1441. {
  1442. ::LoadString(ghInstance, IDM_ASSIGN, szName, 256);
  1443. ::LoadString(ghInstance, IDS_ASSIGN_DESC, szStatus, 256);
  1444. menuitem.lCommandID = IDM_ASSIGN_T;
  1445. menuitem.fSpecialFlags = 0;
  1446. if ((dwFlags & ACTFLG_Assigned) || (data.m_pDetails->pInstallInfo->PathType == SetupNamePath))
  1447. menuitem.fFlags = MFS_DISABLED;
  1448. else
  1449. menuitem.fFlags = 0;
  1450. menuitem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  1451. hr = pContextMenuCallback->AddItem(&menuitem);
  1452. if (FAILED(hr))
  1453. break;
  1454. ::LoadString(ghInstance, IDM_PUBLISH, szName, 256);
  1455. ::LoadString(ghInstance, IDS_PUBLISH_DESC, szStatus, 256);
  1456. menuitem.lCommandID = IDM_PUBLISH_T;
  1457. if ((dwFlags & ACTFLG_Published) || m_fMachine)
  1458. menuitem.fFlags = MFS_DISABLED;
  1459. else
  1460. menuitem.fFlags = 0;
  1461. hr = pContextMenuCallback->AddItem(&menuitem);
  1462. if (FAILED(hr))
  1463. break;
  1464. #if 0
  1465. ::LoadString(ghInstance, IDM_DISABLE, szName, 256);
  1466. ::LoadString(ghInstance, IDS_DISABLE_DESC, szStatus, 256);
  1467. menuitem.lCommandID = IDM_DISABLE_T;
  1468. if (dwFlags & (ACTFLG_Published | ACTFLG_Assigned))
  1469. menuitem.fFlags = 0;
  1470. else
  1471. menuitem.fFlags = MFS_DISABLED;
  1472. hr = pContextMenuCallback->AddItem(&menuitem);
  1473. if (FAILED(hr))
  1474. break;
  1475. #endif
  1476. menuitem.lCommandID = 0;
  1477. menuitem.fFlags = MFT_SEPARATOR;
  1478. menuitem.fSpecialFlags = CCM_SPECIAL_SEPARATOR;
  1479. hr = pContextMenuCallback->AddItem(&menuitem);
  1480. if (FAILED(hr))
  1481. break;
  1482. ::LoadString(ghInstance, IDM_DEL_APP, szName, 256);
  1483. ::LoadString(ghInstance, IDS_DEL_APP_DESC, szStatus, 256);
  1484. menuitem.lCommandID = IDM_DEL_APP;
  1485. menuitem.fFlags = 0;
  1486. menuitem.fSpecialFlags = 0;
  1487. hr = pContextMenuCallback->AddItem(&menuitem);
  1488. if (FAILED(hr))
  1489. break;
  1490. ::LoadString(ghInstance, IDM_REDEPLOY, szName, 256);
  1491. ::LoadString(ghInstance, IDS_REDEPLOY_DESC, szStatus, 256);
  1492. menuitem.lCommandID = IDM_REDEPLOY;
  1493. if (data.m_pDetails->pInstallInfo->PathType == SetupNamePath)
  1494. menuitem.fFlags = MFS_DISABLED;
  1495. else
  1496. menuitem.fFlags = 0;
  1497. hr = pContextMenuCallback->AddItem(&menuitem);
  1498. if (FAILED(hr))
  1499. break;
  1500. menuitem.lCommandID = 0;
  1501. menuitem.fFlags = MFT_SEPARATOR;
  1502. menuitem.fSpecialFlags = CCM_SPECIAL_SEPARATOR;
  1503. hr = pContextMenuCallback->AddItem(&menuitem);
  1504. if (FAILED(hr))
  1505. break;
  1506. }
  1507. }
  1508. } while (FALSE);
  1509. FREE_INTERNAL(pInternal);
  1510. return hr;
  1511. }
  1512. HRESULT CScopePane::GetRSoPCategories(void)
  1513. {
  1514. HRESULT hr = S_OK;
  1515. list <APPCATEGORYINFO> CatList;
  1516. IWbemLocator * pLocator = NULL;
  1517. IWbemServices * pNamespace = NULL;
  1518. IWbemClassObject * pObj = NULL;
  1519. IEnumWbemClassObject * pEnum = NULL;
  1520. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  1521. BSTR strQueryCategories = SysAllocString(TEXT("SELECT * FROM RSOP_ApplicationManagementCategory"));
  1522. BSTR strNamespace = SysAllocString(m_szRSOPNamespace);
  1523. ULONG n = 0;
  1524. hr = CoCreateInstance(CLSID_WbemLocator,
  1525. 0,
  1526. CLSCTX_INPROC_SERVER,
  1527. IID_IWbemLocator,
  1528. (LPVOID *) & pLocator);
  1529. DebugReportFailure(hr, (DM_WARNING, L"GetRSoPCategories: CoCreateInstance failed with 0x%x", hr));
  1530. if (FAILED(hr))
  1531. {
  1532. goto cleanup;
  1533. }
  1534. hr = pLocator->ConnectServer(strNamespace,
  1535. NULL,
  1536. NULL,
  1537. NULL,
  1538. 0,
  1539. NULL,
  1540. NULL,
  1541. &pNamespace);
  1542. DebugReportFailure(hr, (DM_WARNING, L"GetRSoPCategories: pLocator->ConnectServer failed with 0x%x", hr));
  1543. if (FAILED(hr))
  1544. {
  1545. goto cleanup;
  1546. }
  1547. // First perform the query to get the list of categories
  1548. // erase any existing list
  1549. ClearCategories();
  1550. // create a new one
  1551. hr = pNamespace->ExecQuery(strQueryLanguage,
  1552. strQueryCategories,
  1553. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  1554. NULL,
  1555. &pEnum);
  1556. DebugReportFailure(hr, (DM_WARNING, L"GetRSoPCategories: pNamespace->ExecQuery failed with 0x%x", hr));
  1557. if (FAILED(hr))
  1558. {
  1559. goto cleanup;
  1560. }
  1561. do
  1562. {
  1563. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  1564. if (FAILED(hr))
  1565. {
  1566. goto cleanup;
  1567. }
  1568. if (n > 0)
  1569. {
  1570. APPCATEGORYINFO ci;
  1571. memset(&ci, 0, sizeof(APPCATEGORYINFO));
  1572. ci.Locale = 0;
  1573. hr = GetParameter(pObj,
  1574. TEXT("CategoryId"),
  1575. ci.AppCategoryId);
  1576. DebugReportFailure(hr, (DM_WARNING, L"GetRSoPCategories: GetParameter(\"CategoryId\") failed with 0x%x", hr));
  1577. hr = GetParameter(pObj,
  1578. TEXT("Name"),
  1579. ci.pszDescription);
  1580. DebugReportFailure(hr, (DM_WARNING, L"GetRSoPCategories: GetParameter(\"Name\") failed with 0x%x", hr));
  1581. CatList.push_back(ci);
  1582. }
  1583. } while (n > 0);
  1584. // put the list of categories into the proper format so it matches
  1585. // what we would get from the class store
  1586. n = CatList.size();
  1587. if (n > 0)
  1588. {
  1589. m_CatList.pCategoryInfo =
  1590. (APPCATEGORYINFO *)OLEALLOC(sizeof(APPCATEGORYINFO) * n);
  1591. if (m_CatList.pCategoryInfo)
  1592. {
  1593. m_CatList.cCategory = n;
  1594. while (n--)
  1595. {
  1596. m_CatList.pCategoryInfo[n] = *CatList.begin();
  1597. CatList.erase(CatList.begin());
  1598. }
  1599. }
  1600. }
  1601. cleanup:
  1602. SysFreeString(strQueryLanguage);
  1603. SysFreeString(strQueryCategories);
  1604. SysFreeString(strNamespace);
  1605. if (pObj)
  1606. {
  1607. pObj->Release();
  1608. }
  1609. if (pEnum)
  1610. {
  1611. pEnum->Release();
  1612. }
  1613. if (pNamespace)
  1614. {
  1615. pNamespace->Release();
  1616. }
  1617. if (pLocator)
  1618. {
  1619. pLocator->Release();
  1620. }
  1621. return hr;
  1622. }
  1623. HRESULT CScopePane::InitializeADE()
  1624. {
  1625. HRESULT hr = S_OK;
  1626. if ((!m_fRSOP) && (!m_pIClassAdmin))
  1627. {
  1628. // make sure directories are created:
  1629. CreateNestedDirectory ((LPOLESTR)((LPCOLESTR)m_szGPT_Path), NULL);
  1630. // try and get IClassAdmin
  1631. hr = GetClassStore(FALSE);
  1632. }
  1633. return hr;
  1634. }
  1635. void CScopePane::Refresh()
  1636. {
  1637. if (m_fRSOP || ((!m_fBlockAddPackage) && (m_pIClassAdmin)))
  1638. {
  1639. map <MMC_COOKIE, CAppData>::iterator i;
  1640. set <CResultPane *>::iterator i2;
  1641. for (i2 = m_sResultPane.begin(); i2 != m_sResultPane.end(); i2++)
  1642. {
  1643. (*i2)->m_pResult->DeleteAllRsltItems();
  1644. }
  1645. for (i=m_AppData.begin(); i != m_AppData.end(); i++)
  1646. {
  1647. // if (i->second.m_fVisible)
  1648. // {
  1649. // }
  1650. OLESAFE_DELETE(i->second.m_psd);
  1651. FreePackageDetail(i->second.m_pDetails);
  1652. }
  1653. m_AppData.erase(m_AppData.begin(), m_AppData.end());
  1654. m_UpgradeIndex.erase(m_UpgradeIndex.begin(), m_UpgradeIndex.end());
  1655. m_Extensions.erase(m_Extensions.begin(), m_Extensions.end());
  1656. m_lLastAllocated = 0;
  1657. for (i2 = m_sResultPane.begin(); i2 != m_sResultPane.end(); i2++)
  1658. {
  1659. (*i2)->EnumerateResultPane(0);
  1660. }
  1661. }
  1662. }
  1663. STDMETHODIMP CScopePane::Command(long nCommandID, LPDATAOBJECT pDataObject)
  1664. {
  1665. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1666. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  1667. if (!pInternal)
  1668. {
  1669. return E_UNEXPECTED;
  1670. }
  1671. // Note - snap-ins need to look at the data object and determine
  1672. // in what context the command is being called.
  1673. // Handle each of the commands.
  1674. switch (nCommandID)
  1675. {
  1676. case IDM_AUTOINST:
  1677. if (pInternal->m_type == CCT_RESULT)
  1678. {
  1679. CAppData &data = m_AppData[pInternal->m_cookie];
  1680. DWORD dwNewFlags = data.m_pDetails->pInstallInfo->dwActFlags ^ ACTFLG_OnDemandInstall;
  1681. ChangePackageState(data, dwNewFlags, TRUE);
  1682. }
  1683. break;
  1684. case IDM_ASSIGN:
  1685. case IDM_ASSIGN_T:
  1686. if (pInternal->m_type == CCT_RESULT)
  1687. {
  1688. CAppData &data = m_AppData[pInternal->m_cookie];
  1689. DWORD dwNewFlags = data.m_pDetails->pInstallInfo->dwActFlags;
  1690. dwNewFlags &= ~(ACTFLG_Published);
  1691. dwNewFlags |= (ACTFLG_Assigned | ACTFLG_UserInstall | ACTFLG_OnDemandInstall);
  1692. ChangePackageState(data, dwNewFlags, TRUE);
  1693. }
  1694. break;
  1695. case IDM_PUBLISH:
  1696. case IDM_PUBLISH_T:
  1697. if (pInternal->m_type == CCT_RESULT)
  1698. {
  1699. CAppData &data = m_AppData[pInternal->m_cookie];
  1700. DWORD dwNewFlags = data.m_pDetails->pInstallInfo->dwActFlags;
  1701. dwNewFlags &= ~ACTFLG_Assigned;
  1702. dwNewFlags |= ACTFLG_Published | ACTFLG_UserInstall;
  1703. ChangePackageState(data, dwNewFlags, TRUE);
  1704. }
  1705. break;
  1706. case IDM_DISABLE:
  1707. case IDM_DISABLE_T:
  1708. if (pInternal->m_type == CCT_RESULT)
  1709. {
  1710. CAppData &data = m_AppData[pInternal->m_cookie];
  1711. DWORD dwNewFlags = data.m_pDetails->pInstallInfo->dwActFlags;
  1712. dwNewFlags &= ~(ACTFLG_OnDemandInstall | ACTFLG_Assigned | ACTFLG_UserInstall | ACTFLG_Published);
  1713. ChangePackageState(data, dwNewFlags, TRUE);
  1714. }
  1715. break;
  1716. case IDM_REDEPLOY:
  1717. {
  1718. CAppData &data = m_AppData[pInternal->m_cookie];
  1719. CString sz;
  1720. sz.LoadString(IDS_REDEPLOYWARNING);
  1721. int iReturn = IDNO;
  1722. m_pConsole->MessageBox( sz,
  1723. data.m_pDetails->pszPackageName,
  1724. MB_YESNO,
  1725. &iReturn);
  1726. if (IDYES == iReturn)
  1727. {
  1728. CHourglass hourglass;
  1729. //CString szScriptPath = data.m_pDetails->pInstallInfo->pszScriptPath;
  1730. CString szScriptPath = m_szGPT_Path;
  1731. DWORD dwRevision;
  1732. HRESULT hr = S_OK;
  1733. BOOL bStatus;
  1734. szScriptPath += L"\\temp.aas";
  1735. CString szTransformList = L"";
  1736. int i;
  1737. if (data.m_pDetails->cSources > 1)
  1738. {
  1739. CString szSource = data.m_pDetails->pszSourceList[0];
  1740. int nChars = 1 + szSource.ReverseFind(L'\\');
  1741. BOOL fTransformsAtSource = TRUE;
  1742. for (i = 1; i < data.m_pDetails->cSources && TRUE == fTransformsAtSource; i++)
  1743. {
  1744. if (0 == wcsncmp(szSource, data.m_pDetails->pszSourceList[i], nChars))
  1745. {
  1746. // make sure there isn't a sub-path
  1747. int n = nChars;
  1748. while (0 != data.m_pDetails->pszSourceList[i][n] && TRUE == fTransformsAtSource)
  1749. {
  1750. if (data.m_pDetails->pszSourceList[i][n] == L'\\')
  1751. {
  1752. fTransformsAtSource = FALSE;
  1753. }
  1754. n++;
  1755. }
  1756. }
  1757. else
  1758. {
  1759. fTransformsAtSource = FALSE;
  1760. }
  1761. }
  1762. if (fTransformsAtSource)
  1763. {
  1764. szTransformList = L"@";
  1765. }
  1766. else
  1767. {
  1768. szTransformList = L"|";
  1769. nChars = 0;
  1770. }
  1771. for (i = 1; i < data.m_pDetails->cSources; i++)
  1772. {
  1773. if (i > 1)
  1774. {
  1775. szTransformList += L";";
  1776. }
  1777. szTransformList += &data.m_pDetails->pszSourceList[i][nChars];
  1778. }
  1779. }
  1780. // disable MSI ui
  1781. MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
  1782. // build the script file
  1783. DWORD dwPlatform;
  1784. if ( CAppData::Is64Bit( data.m_pDetails ) )
  1785. {
  1786. dwPlatform = MSIARCHITECTUREFLAGS_IA64;
  1787. }
  1788. else
  1789. {
  1790. dwPlatform = MSIARCHITECTUREFLAGS_X86;
  1791. }
  1792. UINT uMsiStatus = MsiAdvertiseProductEx(
  1793. data.m_pDetails->pszSourceList[0],
  1794. szScriptPath,
  1795. szTransformList,
  1796. LANGIDFROMLCID(data.m_pDetails->pPlatformInfo->prgLocale[0]),
  1797. dwPlatform,
  1798. 0);
  1799. if (uMsiStatus)
  1800. {
  1801. DebugMsg((DM_WARNING, TEXT("MsiAdvertiseProduct failed with %u"), uMsiStatus));
  1802. hr = HRESULT_FROM_WIN32(uMsiStatus);
  1803. }
  1804. if (SUCCEEDED(hr))
  1805. {
  1806. dwRevision = data.m_pDetails->pInstallInfo->dwRevision + 1;
  1807. hr = m_pIClassAdmin->ChangePackageProperties(data.m_pDetails->pszPackageName,
  1808. NULL,
  1809. NULL,
  1810. NULL,
  1811. NULL,
  1812. NULL,
  1813. &dwRevision);
  1814. }
  1815. if (SUCCEEDED(hr))
  1816. {
  1817. // delete the old script
  1818. bStatus = DeleteFile(data.m_pDetails->pInstallInfo->pszScriptPath);
  1819. // rename the new one
  1820. if ( bStatus )
  1821. bStatus = MoveFile(szScriptPath, data.m_pDetails->pInstallInfo->pszScriptPath);
  1822. data.m_pDetails->pInstallInfo->dwRevision = dwRevision;
  1823. if ( bStatus )
  1824. {
  1825. if (FAILED(m_pIGPEInformation->PolicyChanged(m_fMachine, TRUE, &guidExtension,
  1826. m_fMachine ? &guidMachSnapin
  1827. : &guidUserSnapin)))
  1828. {
  1829. ReportPolicyChangedError(m_hwndMainWindow);
  1830. }
  1831. }
  1832. else
  1833. hr = HRESULT_FROM_WIN32(GetLastError());
  1834. }
  1835. if ( ! SUCCEEDED(hr) )
  1836. {
  1837. DebugMsg((DM_WARNING, TEXT("ChangePackageProperties failed with 0x%x"), hr));
  1838. // display failure message
  1839. sz.LoadString(IDS_REDEPLOYERROR);
  1840. m_pConsole->MessageBox(sz,
  1841. data.m_pDetails->pszPackageName,
  1842. MB_OK | MB_ICONEXCLAMATION, NULL);
  1843. }
  1844. }
  1845. }
  1846. break;
  1847. case IDM_ADD_APP:
  1848. {
  1849. if (!m_fBlockAddPackage)
  1850. {
  1851. m_fBlockAddPackage=TRUE;
  1852. CString szExtension;
  1853. CString szFilter;
  1854. szExtension.LoadString(IDS_DEF_EXTENSION);
  1855. if (m_fMachine)
  1856. {
  1857. szFilter.LoadString(IDS_EXTENSION_FILTER_M);
  1858. }
  1859. else
  1860. szFilter.LoadString(IDS_EXTENSION_FILTER);
  1861. OPENFILENAME ofn;
  1862. memset(&ofn, 0, sizeof(ofn));
  1863. ofn.lStructSize = sizeof(ofn);
  1864. ofn.hwndOwner = GetActiveWindow();
  1865. ofn.hInstance = ghInstance;
  1866. TCHAR lpstrFilter[MAX_PATH];
  1867. wcsncpy(lpstrFilter, szFilter, MAX_PATH);
  1868. ofn.lpstrFilter = lpstrFilter;
  1869. TCHAR szFileTitle[MAX_PATH];
  1870. TCHAR szFile[MAX_PATH];
  1871. szFile[0] = NULL;
  1872. ofn.lpstrFile = szFile;
  1873. ofn.nMaxFile = MAX_PATH;
  1874. ofn.lpstrFileTitle = szFileTitle;
  1875. ofn.nMaxFileTitle = MAX_PATH;
  1876. ofn.lpstrInitialDir = m_ToolDefaults.szStartPath;
  1877. ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
  1878. ofn.lpstrDefExt = szExtension;
  1879. int iBreak = 0;
  1880. while (lpstrFilter[iBreak])
  1881. {
  1882. if (lpstrFilter[iBreak] == TEXT('|'))
  1883. {
  1884. lpstrFilter[iBreak] = 0;
  1885. }
  1886. iBreak++;
  1887. }
  1888. if (GetOpenFileName(&ofn))
  1889. {
  1890. CHourglass hourglass;
  1891. CString szPackagePath;
  1892. HRESULT hr = E_FAIL;
  1893. TCHAR szFile[MAX_PATH];
  1894. TCHAR * szNextFile = ofn.lpstrFile + ofn.nFileOffset;
  1895. TCHAR * szFileTitle = szFile + ofn.nFileOffset;
  1896. _tcscpy(szFile, ofn.lpstrFile);
  1897. if (0 == szFile[ofn.nFileOffset - 1])
  1898. {
  1899. // this is a list of files (not just one)
  1900. // need to put a slash here so it will work
  1901. szFile[ofn.nFileOffset - 1] = TEXT('\\');
  1902. }
  1903. TCHAR * szFileExtension;
  1904. // don't allow deployment over http or ftp
  1905. if (_wcsnicmp(ofn.lpstrFile, TEXT("http:"), 5) == 0
  1906. ||
  1907. _wcsnicmp(ofn.lpstrFile, TEXT("ftp:"), 4) == 0)
  1908. {
  1909. CString sz;
  1910. sz.LoadString(IDS_ILLEGAL_PATH);
  1911. int iReturn = IDNO;
  1912. m_pConsole->MessageBox(sz, szPackagePath,
  1913. MB_OK | MB_ICONEXCLAMATION,
  1914. &iReturn);
  1915. goto skip_deployment;
  1916. }
  1917. // at this point I have a path and I have a list of file names
  1918. do
  1919. {
  1920. _tcscpy(szFileTitle, szNextFile);
  1921. hr = GetUNCPath (szFile, szPackagePath);
  1922. DebugMsg((DM_VERBOSE, TEXT("GetUNCPath(%s) returned %s"), szFile, szPackagePath));
  1923. if (FAILED(hr))
  1924. {
  1925. CString sz;
  1926. sz.LoadString(IDS_NO_UNIVERSAL_NAME);
  1927. int iReturn = IDNO;
  1928. m_pConsole->MessageBox(sz, szPackagePath,
  1929. MB_YESNO | MB_ICONEXCLAMATION,
  1930. &iReturn);
  1931. if (IDYES != iReturn)
  1932. {
  1933. goto skip_deployment;
  1934. }
  1935. }
  1936. szFileExtension = _tcsrchr(szFile, TEXT('.'));
  1937. if ((szFileExtension) &&
  1938. (0 == _wcsicmp(szFileExtension, L".zap")))
  1939. {
  1940. if (m_fMachine)
  1941. {
  1942. CString szText;
  1943. CString szTitle;
  1944. szText.LoadString(IDS_NO_ZAPS_ALLOWED);
  1945. // only allow ZAP files to be deployed to users
  1946. m_pConsole->MessageBox(
  1947. szText,
  1948. szTitle,
  1949. MB_OK | MB_ICONEXCLAMATION,
  1950. NULL);
  1951. hr = E_FAIL;
  1952. }
  1953. else
  1954. {
  1955. hr = AddZAPPackage(szPackagePath, szFileTitle);
  1956. }
  1957. }
  1958. else
  1959. {
  1960. hr = AddMSIPackage(szPackagePath, szFileTitle);
  1961. }
  1962. szNextFile += _tcslen(szNextFile) + 1;
  1963. } while (szNextFile[0]);
  1964. skip_deployment:
  1965. // Notify clients of change
  1966. if (SUCCEEDED(hr) && m_pIGPEInformation)
  1967. {
  1968. if (FAILED(m_pIGPEInformation->PolicyChanged(m_fMachine, TRUE, &guidExtension,
  1969. m_fMachine ? &guidMachSnapin
  1970. : &guidUserSnapin)))
  1971. {
  1972. ReportPolicyChangedError(m_hwndMainWindow);
  1973. }
  1974. }
  1975. }
  1976. m_fBlockAddPackage = FALSE;
  1977. }
  1978. else
  1979. {
  1980. // consider a message here
  1981. }
  1982. }
  1983. break;
  1984. case IDM_WINNER:
  1985. case IDM_REMOVED:
  1986. case IDM_FAILED:
  1987. case IDM_ARP:
  1988. m_iViewState = nCommandID;
  1989. {
  1990. // change toolbar state
  1991. set <CResultPane *>::iterator i;
  1992. for (i = m_sResultPane.begin(); i != m_sResultPane.end(); i++)
  1993. {
  1994. if ((*i)->m_pToolbar)
  1995. {
  1996. (*i)->m_pToolbar->SetButtonState(IDM_WINNER,
  1997. BUTTONPRESSED,
  1998. FALSE);
  1999. (*i)->m_pToolbar->SetButtonState(IDM_REMOVED,
  2000. BUTTONPRESSED,
  2001. FALSE);
  2002. (*i)->m_pToolbar->SetButtonState(IDM_ARP,
  2003. BUTTONPRESSED,
  2004. FALSE);
  2005. (*i)->m_pToolbar->SetButtonState(nCommandID,
  2006. BUTTONPRESSED,
  2007. TRUE);
  2008. }
  2009. }
  2010. }
  2011. // deliberately fall through to REFRESH
  2012. case IDM_REFRESH:
  2013. Refresh();
  2014. //
  2015. // In logging mode, we need to show a message box to the user
  2016. // in the case that ARP view is empty so that users are clear
  2017. // that this may be because ARP has not been run yet
  2018. //
  2019. if ( m_fRSOP &&
  2020. ( IDM_ARP == nCommandID ) &&
  2021. ( m_dwRSOPFlags & RSOP_INFO_FLAG_DIAGNOSTIC_MODE ) &&
  2022. ! m_fDisplayedRsopARPWarning &&
  2023. ( m_AppData.end() == m_AppData.begin() ) )
  2024. {
  2025. CString szTitle;
  2026. CString szText;
  2027. szTitle.LoadString(IDS_RSOP_ARP_WARNING_TITLE);
  2028. szText.LoadString(IDS_RSOP_ARP_WARNING);
  2029. int iReturn;
  2030. m_pConsole->MessageBox(szText,
  2031. szTitle,
  2032. MB_OK,
  2033. &iReturn);
  2034. m_fDisplayedRsopARPWarning = TRUE;
  2035. }
  2036. break;
  2037. case IDM_DEL_APP:
  2038. if (pInternal->m_type == CCT_RESULT)
  2039. {
  2040. CAppData & data = m_AppData[pInternal->m_cookie];
  2041. if ((data.m_pDetails->pInstallInfo->PathType == SetupNamePath))
  2042. {
  2043. // this is a legacy app it can't be uninstalled
  2044. CString szTitle;
  2045. CString szText;
  2046. szTitle.LoadString(IDS_REMOVE_LEGACY_TITLE);
  2047. szText.LoadString(IDS_REMOVE_LEGACY_TEXT);
  2048. int iReturn = IDNO;
  2049. m_pConsole->MessageBox(szText,
  2050. szTitle,
  2051. MB_YESNO,
  2052. &iReturn);
  2053. if (IDYES == iReturn)
  2054. {
  2055. RemovePackage(pInternal->m_cookie, FALSE, FALSE);
  2056. }
  2057. }
  2058. else
  2059. {
  2060. CRemove dlg;
  2061. // Activate the theme context in order to theme this dialog
  2062. CThemeContextActivator themer;
  2063. int iReturn = dlg.DoModal();
  2064. if (IDOK == iReturn)
  2065. {
  2066. switch (dlg.m_iState)
  2067. {
  2068. case 0:
  2069. RemovePackage(pInternal->m_cookie, TRUE, FALSE);
  2070. break;
  2071. case 1:
  2072. RemovePackage(pInternal->m_cookie, FALSE, FALSE);
  2073. break;
  2074. }
  2075. }
  2076. }
  2077. }
  2078. break;
  2079. default:
  2080. break;
  2081. }
  2082. return S_OK;
  2083. }
  2084. static PFNDSCREATEISECINFO pDSCreateISecurityInfoObject = NULL;
  2085. static HINSTANCE hInst_dssec = NULL;
  2086. STDAPI DSCreateISecurityInfoObject(LPCWSTR pwszObjectPath,
  2087. LPCWSTR pwszObjectClass,
  2088. DWORD dwFlags,
  2089. LPSECURITYINFO * ppSI,
  2090. PFNREADOBJECTSECURITY pfnReadSD,
  2091. PFNWRITEOBJECTSECURITY pfnWriteSD,
  2092. LPARAM lpContext)
  2093. {
  2094. if (NULL == pDSCreateISecurityInfoObject)
  2095. {
  2096. if (NULL == hInst_dssec)
  2097. {
  2098. hInst_dssec = LoadLibrary(L"dssec.dll");
  2099. if (NULL == hInst_dssec)
  2100. {
  2101. return E_UNEXPECTED;
  2102. }
  2103. }
  2104. pDSCreateISecurityInfoObject = (PFNDSCREATEISECINFO)
  2105. GetProcAddress(hInst_dssec, "DSCreateISecurityInfoObject");
  2106. if (NULL == pDSCreateISecurityInfoObject)
  2107. {
  2108. return E_UNEXPECTED;
  2109. }
  2110. }
  2111. return pDSCreateISecurityInfoObject(pwszObjectPath, pwszObjectClass, dwFlags, ppSI, pfnReadSD, pfnWriteSD, lpContext);
  2112. }
  2113. //+--------------------------------------------------------------------------
  2114. //
  2115. // Function: GetUNCPath
  2116. //
  2117. // Synopsis: This function takes in a driver based path and converts
  2118. // it to a UNC path
  2119. //
  2120. // Arguments:
  2121. // [in] [szPath] - The drive based path
  2122. // [out][szUNCPath] - The UNC path
  2123. //
  2124. // Returns:
  2125. // S_OK - If the function succeeds in obtaining a UNC path
  2126. // E_FAIL - If the function cannot obtain a UNC path
  2127. //
  2128. // History: 5/20/1998 RahulTh created
  2129. //
  2130. // Notes: If the function cannot obtain a UNC path, it simply copies szPath
  2131. // into szUNCPath on return.
  2132. //
  2133. //---------------------------------------------------------------------------
  2134. HRESULT GetUNCPath (LPCOLESTR szPath, CString& szUNCPath)
  2135. {
  2136. TCHAR* lpszUNCName;
  2137. UNIVERSAL_NAME_INFO * pUni;
  2138. ULONG cbSize;
  2139. HRESULT hr;
  2140. DWORD retVal;
  2141. szUNCPath.Empty(); //safety measure
  2142. lpszUNCName = new TCHAR[MAX_PATH];
  2143. pUni = (UNIVERSAL_NAME_INFO*) lpszUNCName;
  2144. cbSize = MAX_PATH * sizeof(TCHAR);
  2145. retVal = WNetGetUniversalName(szPath,
  2146. UNIVERSAL_NAME_INFO_LEVEL,
  2147. (LPVOID) pUni,
  2148. &cbSize);
  2149. if (ERROR_MORE_DATA == retVal) //if the buffer was not large enough
  2150. {
  2151. delete [] pUni;
  2152. pUni = (UNIVERSAL_NAME_INFO *) new BYTE [cbSize];
  2153. retVal = WNetGetUniversalName(szPath,
  2154. UNIVERSAL_NAME_INFO_LEVEL,
  2155. pUni,
  2156. &cbSize);
  2157. }
  2158. if (NO_ERROR == retVal)
  2159. {
  2160. szUNCPath = pUni->lpUniversalName;
  2161. hr = S_OK;
  2162. }
  2163. else
  2164. {
  2165. szUNCPath = szPath;
  2166. if (0 != wcsncmp(szPath, L"\\\\", 2))
  2167. hr = E_FAIL; //probably not a remote share.
  2168. else
  2169. hr = S_OK; //probably a remote share.
  2170. }
  2171. delete[] pUni;
  2172. return hr;
  2173. }
  2174. //+--------------------------------------------------------------------------
  2175. //
  2176. // Function: LogADEEvent
  2177. //
  2178. // Synopsis: logs an ADE event in the event log
  2179. //
  2180. // Arguments: [wType] - type of event
  2181. // [dwEventID] - event ID
  2182. // [hr] - HRESULT that triggered the event to be logged
  2183. // [szOptional] - additional descriptive text used by some events
  2184. //
  2185. // Returns: nothing
  2186. //
  2187. // Modifies: nothing
  2188. //
  2189. // History: 05-27-1999 stevebl Created
  2190. // 04-28-2000 stevebl Modified to allow more complex logging
  2191. //
  2192. // Notes: We attempt to use FormatMessage to craft a legible message
  2193. // but in the case that it fails, we just log the HRESULT.
  2194. //
  2195. //---------------------------------------------------------------------------
  2196. void LogADEEvent(WORD wType, DWORD dwEventID, HRESULT hr, LPCWSTR szOptional)
  2197. {
  2198. TCHAR szBuffer[256];
  2199. DWORD dw = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  2200. NULL,
  2201. hr,
  2202. 0,
  2203. szBuffer,
  2204. sizeof(szBuffer) / sizeof(szBuffer[0]),
  2205. NULL);
  2206. if (0 == dw)
  2207. {
  2208. // FormatMessage failed.
  2209. // We'll have to come up with some sort of reasonable message.
  2210. wsprintf(szBuffer, TEXT("(HRESULT: 0x%lX)"), hr);
  2211. }
  2212. HANDLE hEventLog = OpenEventLog( NULL, ADE_EVENT_SOURCE );
  2213. if (hEventLog)
  2214. {
  2215. LPCWSTR rgsz[2];
  2216. rgsz[0] = szBuffer;
  2217. rgsz[1] = szOptional;
  2218. ReportEvent(hEventLog,
  2219. wType,
  2220. 0,
  2221. dwEventID,
  2222. NULL,
  2223. NULL == szOptional ? 1 : 2,
  2224. sizeof(hr),
  2225. rgsz,
  2226. &hr);
  2227. CloseEventLog(hEventLog);
  2228. }
  2229. }
  2230. //+--------------------------------------------------------------------------
  2231. //
  2232. // Function: ReportGeneralPropertySheetError
  2233. //
  2234. // Synopsis: Pops up a message box indicating why changes to a property
  2235. // page could not be applies and logs the error in the event log.
  2236. //
  2237. // Arguments: [sz] - Title bar text
  2238. // [hr] - hresult of the error
  2239. //
  2240. // Returns: nothing
  2241. //
  2242. // History: 9-30-1998 stevebl Created
  2243. //
  2244. //---------------------------------------------------------------------------
  2245. void ReportGeneralPropertySheetError(HWND hwnd, LPCWSTR sz, HRESULT hr)
  2246. {
  2247. LogADEEvent(EVENTLOG_ERROR_TYPE, EVENT_ADE_GENERAL_ERROR, hr);
  2248. CString szMessage;
  2249. szMessage.LoadString(IDS_GENERALERROR);
  2250. MessageBox( hwnd,
  2251. szMessage,
  2252. sz,
  2253. MB_OK | MB_ICONEXCLAMATION);
  2254. }
  2255. void ReportPolicyChangedError(HWND hwnd)
  2256. {
  2257. CString szMessage;
  2258. szMessage.LoadString(IDS_ERRORPOLICYCHANGED);
  2259. MessageBox(hwnd,
  2260. szMessage,
  2261. NULL,
  2262. MB_OK | MB_ICONEXCLAMATION);
  2263. }
  2264. //+--------------------------------------------------------------------------
  2265. //
  2266. // Function: LoadHelpInfo
  2267. //
  2268. // Synopsis: routine that loads and locks the help mapping resources
  2269. //
  2270. // Arguments: [nIDD] - ID of the dialog making the help request
  2271. //
  2272. // Returns: handle to the locked and loaded mapping table
  2273. //
  2274. // History: 10-22-1998 stevebl Created
  2275. //
  2276. //---------------------------------------------------------------------------
  2277. LPDWORD LoadHelpInfo(UINT nIDD)
  2278. {
  2279. HRSRC hrsrc = FindResource(ghInstance, MAKEINTRESOURCE(nIDD),
  2280. MAKEINTRESOURCE(RT_HELPINFO));
  2281. if (hrsrc == NULL)
  2282. return NULL;
  2283. HGLOBAL hHelpInfo = LoadResource(ghInstance, hrsrc);
  2284. if (hHelpInfo == NULL)
  2285. return NULL;
  2286. LPDWORD lpdwHelpInfo = (LPDWORD)LockResource(hHelpInfo);
  2287. return lpdwHelpInfo;
  2288. }
  2289. #define RSOP_HELP_FILE TEXT("gpedit.hlp")
  2290. //+--------------------------------------------------------------------------
  2291. //
  2292. // Function: StandardHelp
  2293. //
  2294. // Synopsis: Standardized routine for bringing up context sensitive help.
  2295. //
  2296. // Arguments: [hWnd] - window that needs help
  2297. // [nIDD] - ID of the dialog making the request
  2298. // Notes:
  2299. //
  2300. //
  2301. // History: 10-22-1998 stevebl modified from the OLEDLG sources
  2302. //
  2303. //---------------------------------------------------------------------------
  2304. void WINAPI StandardHelp(HWND hWnd, UINT nIDD, BOOL fRsop /* = FALSE */ )
  2305. {
  2306. LPDWORD lpdwHelpInfo = LoadHelpInfo(nIDD);
  2307. if (lpdwHelpInfo == NULL)
  2308. {
  2309. DebugMsg((DL_VERBOSE, TEXT("Warning: unable to load help information (RT_HELPINFO)\n")));
  2310. return;
  2311. }
  2312. WinHelp(hWnd, fRsop ? RSOP_HELP_FILE : HELP_FILE, HELP_WM_HELP, (DWORD_PTR)lpdwHelpInfo);
  2313. }
  2314. //+--------------------------------------------------------------------------
  2315. //
  2316. // Function: StandardContextMenu
  2317. //
  2318. // Synopsis: Standardized routine for bringing up context menu based help.
  2319. //
  2320. // Arguments: [hWnd] -
  2321. // [nIDD] - ID of the dialog making the request
  2322. //
  2323. // History: 10-22-1998 stevebl modified from the OLEDLG sources
  2324. //
  2325. //---------------------------------------------------------------------------
  2326. void WINAPI StandardContextMenu(HWND hWnd, UINT nIDD, BOOL fRsop /* = FALSE */ )
  2327. {
  2328. LPDWORD lpdwHelpInfo = LoadHelpInfo(nIDD);
  2329. if (lpdwHelpInfo == NULL)
  2330. {
  2331. DebugMsg((DL_VERBOSE, TEXT("Warning: unable to load help information (RT_HELPINFO)\n")));
  2332. return;
  2333. }
  2334. WinHelp(hWnd, fRsop ? RSOP_HELP_FILE : HELP_FILE, HELP_CONTEXTMENU, (DWORD_PTR)lpdwHelpInfo);
  2335. }
  2336. //+--------------------------------------------------------------------------
  2337. //
  2338. // Function: CreateThemedPropertyPage
  2339. //
  2340. // Synopsis: Helper function to make sure that property pages put up
  2341. // by the snap-in are themed.
  2342. //
  2343. // Arguments:
  2344. //
  2345. // Returns:
  2346. //
  2347. // History: 4/20/2001 RahulTh created
  2348. //
  2349. // Notes:
  2350. //
  2351. //---------------------------------------------------------------------------
  2352. HPROPSHEETPAGE CreateThemedPropertySheetPage(AFX_OLDPROPSHEETPAGE* psp)
  2353. {
  2354. PROPSHEETPAGE_V3 sp_v3 = {0};
  2355. CopyMemory (&sp_v3, psp, psp->dwSize);
  2356. sp_v3.dwSize = sizeof(sp_v3);
  2357. return (::CreatePropertySheetPage (&sp_v3));
  2358. }