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.

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