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.

154 lines
4.0 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. // DynExten.cpp : enumerates installed services on (possibly remote) computer
  3. //
  4. // HISTORY
  5. // 30-Oct-97 JonN Creation.
  6. /////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include "macros.h"
  9. USE_HANDLE_MACROS("MMCFMGMT(dynexten.cpp)")
  10. #include "compdata.h"
  11. #include "cookie.h"
  12. #include "regkey.h" // AMC::CRegKey
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. const TCHAR SERVICES_KEY[] = TEXT("System\\CurrentControlSet\\Control\\Server Applications");
  19. const TCHAR CLSID_KEY[] = TEXT("Clsid\\");
  20. HRESULT DynextenCheckInstall( const GUID& guidExtension, const TCHAR* pszExtension )
  21. {
  22. HRESULT hr = S_OK;
  23. #ifdef USE_CLASS_STORE
  24. IClassAccess* pIClassAccess = NULL;
  25. #endif
  26. try
  27. {
  28. TCHAR achRegPath[ MAX_PATH ];
  29. _tcscpy( achRegPath, CLSID_KEY );
  30. _tcsncat( achRegPath, pszExtension, MAX_PATH - _tcslen(achRegPath) );
  31. achRegPath[MAX_PATH-1] = TEXT('\0'); // JonN 11/21/00 PREFIX 226785/226786
  32. AMC::CRegKey regkeyInstalled;
  33. BOOL fFound = regkeyInstalled.OpenKeyEx( HKEY_CLASSES_ROOT, achRegPath, KEY_READ );
  34. if ( fFound )
  35. {
  36. return S_OK; // it is already installed
  37. }
  38. // CODEWORK It would be more efficient to access the Class Store directly
  39. // by calling CoGetClassAccess, then IClassAccess->GetAppInfo(), then CoInstall().
  40. #ifdef USE_CLASS_STORE
  41. // now we have to get the Class Store to install it
  42. do { // false loop
  43. hr = CoGetClassAccess( &pIClassAccess );
  44. if ( FAILED(hr) )
  45. break;
  46. // now what???
  47. } while (FALSE); // false loop
  48. #else
  49. IUnknown* pIUnknown = NULL;
  50. hr = ::CoCreateInstance( guidExtension,
  51. NULL,
  52. CLSCTX_INPROC,
  53. IID_IComponentData,
  54. (PVOID*)&pIUnknown );
  55. if (NULL != pIUnknown)
  56. pIUnknown->Release();
  57. // allow hr to fall through
  58. #endif
  59. }
  60. catch (COleException* e)
  61. {
  62. e->Delete();
  63. return E_FAIL;
  64. }
  65. #ifdef USE_CLASS_STORE
  66. if (NULL != pIClassAccess)
  67. pIClassAccess->Release();
  68. #endif
  69. return hr;
  70. }
  71. //
  72. // CMyComputerComponentData
  73. //
  74. static CLSID CLSID_DnsSnapin =
  75. { 0x80105023, 0x50B1, 0x11d1, { 0xB9, 0x30, 0x00, 0xA0, 0xC9, 0xA0, 0x6D, 0x2D } };
  76. static CLSID CLSID_FileServiceManagementExt = {0x58221C69,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  77. HRESULT CMyComputerComponentData::ExpandServerApps(
  78. HSCOPEITEM hParent,
  79. CMyComputerCookie* pcookie )
  80. {
  81. try
  82. {
  83. AMC::CRegKey regkeyServices;
  84. BOOL fFound = TRUE;
  85. if (NULL == pcookie->QueryTargetServer())
  86. {
  87. fFound = regkeyServices.OpenKeyEx( HKEY_LOCAL_MACHINE, SERVICES_KEY, KEY_READ );
  88. }
  89. else
  90. {
  91. AMC::CRegKey regkeyRemoteComputer;
  92. regkeyRemoteComputer.ConnectRegistry(
  93. const_cast<LPTSTR>(pcookie->QueryTargetServer()) );
  94. fFound = regkeyServices.OpenKeyEx( regkeyRemoteComputer, SERVICES_KEY, KEY_READ );
  95. }
  96. if ( !fFound )
  97. {
  98. return S_OK; // CODEWORK what return code?
  99. }
  100. CComQIPtr<IConsoleNameSpace2, &IID_IConsoleNameSpace2> pIConsoleNameSpace2
  101. = m_pConsole;
  102. if ( !pIConsoleNameSpace2 )
  103. {
  104. ASSERT(FALSE);
  105. return E_UNEXPECTED;
  106. }
  107. TCHAR achValue[ MAX_PATH ];
  108. DWORD iSubkey;
  109. DWORD cchValue;
  110. for ( iSubkey = 0;
  111. cchValue = sizeof(achValue)/sizeof(TCHAR),
  112. regkeyServices.EnumValue(
  113. iSubkey,
  114. achValue,
  115. &cchValue );
  116. iSubkey++ )
  117. {
  118. GUID guidExtension;
  119. HRESULT hr = ::CLSIDFromString( achValue, &guidExtension );
  120. if ( !SUCCEEDED(hr) )
  121. continue;
  122. hr = DynextenCheckInstall( guidExtension, achValue );
  123. if ( !SUCCEEDED(hr) )
  124. continue;
  125. hr = pIConsoleNameSpace2->AddExtension( hParent, &guidExtension );
  126. // ignore the return value
  127. }
  128. }
  129. catch (COleException* e)
  130. {
  131. e->Delete();
  132. return S_OK; // CODEWORK what return code?
  133. }
  134. return S_OK;
  135. }