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.

132 lines
4.3 KiB

  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <atlbase.h>
  4. #include <atlimpl.cpp>
  5. #define CLSID_LENGTH 256
  6. #define MAX_PATH_LEN 2048
  7. const CHAR g_MMCVBSnapinsKey[] = "Software\\Microsoft\\Visual Basic\\6.0\\SnapIns";
  8. const CHAR g_MMCKey[] = "Software\\Microsoft\\MMC";
  9. const CHAR g_SnapIns[] = "SnapIns";
  10. const CHAR g_NodeTypes[] = "NodeTypes";
  11. // Remove the MMC VB snapin entries from the registry
  12. int __cdecl main(int argc, char* argv[])
  13. {
  14. HRESULT hr = CoInitialize(NULL);
  15. if (FAILED(hr))
  16. return 0;
  17. BOOL bOleInitialized = TRUE;
  18. do
  19. {
  20. // Open HKLM\Software\Microsoft\Visual Basic\6.0\SnapIns.
  21. LONG lRetVal = 0;
  22. ATL::CRegKey regVBSnapinsKey;
  23. lRetVal = regVBSnapinsKey.Open(HKEY_LOCAL_MACHINE, g_MMCVBSnapinsKey, KEY_READ);
  24. // If no VB Snapins then return.
  25. if (ERROR_SUCCESS != lRetVal)
  26. break;
  27. ATL::CRegKey regCLSIDKey;
  28. lRetVal = regCLSIDKey.Open(HKEY_CLASSES_ROOT, "CLSID");
  29. ATLASSERT(ERROR_SUCCESS == lRetVal);
  30. if (ERROR_SUCCESS != lRetVal)
  31. break;
  32. ATL::CRegKey regMMCKey;
  33. // Open the other required keys.
  34. lRetVal = regMMCKey.Open(HKEY_LOCAL_MACHINE, g_MMCKey, KEY_READ | KEY_WRITE);
  35. // If MMC Key remove VB Snapins key.
  36. if (ERROR_SUCCESS != lRetVal)
  37. {
  38. // BUGBUG
  39. break;
  40. }
  41. // Enumerate the regVBSnapinsKey, this yields NodeTypeGuid key with
  42. // default value as snapin class id.
  43. CHAR szNodeType[CLSID_LENGTH];
  44. CHAR szClsid[CLSID_LENGTH];
  45. DWORD dwLength;
  46. for (DWORD dwIndex = 0; TRUE; dwIndex++)
  47. {
  48. lRetVal = RegEnumKeyEx( (HKEY)regVBSnapinsKey, 0, szNodeType, &dwLength, NULL, NULL, NULL, NULL);
  49. if ( (lRetVal == ERROR_NO_MORE_ITEMS) ||
  50. (lRetVal != ERROR_SUCCESS) )
  51. break;
  52. // Got the NodeTypeGuid value, now open that key.
  53. ATL::CRegKey regTempKey;
  54. lRetVal = regTempKey.Open((HKEY)regVBSnapinsKey, szNodeType, KEY_READ);
  55. if (ERROR_SUCCESS != lRetVal)
  56. continue;
  57. // Read the default value (Snapin CLSID).
  58. dwLength = CLSID_LENGTH;
  59. lRetVal = regTempKey.QueryValue(szClsid, NULL, &dwLength);
  60. if (ERROR_SUCCESS != lRetVal)
  61. continue;
  62. #if 0 // Disable this code for this release
  63. // Now we have the snapin class id
  64. // Find the inproc server, Load it and call its DllUnRegisterServer
  65. lRetVal = regTempKey.Open((HKEY) regCLSIDKey, szClsid, KEY_READ);
  66. ATLASSERT(ERROR_SUCCESS == lRetVal);
  67. if (ERROR_SUCCESS != lRetVal)
  68. continue;
  69. lRetVal = regTempKey.Open((HKEY) regTempKey, TEXT("InprocServer32"), KEY_READ);
  70. ATLASSERT(ERROR_SUCCESS == lRetVal);
  71. if (ERROR_SUCCESS != lRetVal)
  72. continue;
  73. TCHAR szPath[MAX_PATH_LEN];
  74. dwLength = MAX_PATH_LEN;
  75. lRetVal = regTempKey.QueryValue(szPath, NULL, &dwLength);
  76. ATLASSERT(ERROR_SUCCESS == lRetVal);
  77. if (ERROR_SUCCESS != lRetVal)
  78. continue;
  79. HINSTANCE hInstance = LoadLibraryEx(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  80. if (hInstance && bOleInitialized)
  81. {
  82. HRESULT (STDAPICALLTYPE* lpDllEntryPoint)(void);
  83. (FARPROC&) lpDllEntryPoint = GetProcAddress(hInstance, "DllUnregisterServer");
  84. if (lpDllEntryPoint)
  85. hr = (*lpDllEntryPoint)();
  86. FreeLibrary(hInstance);
  87. }
  88. #endif // #if 0
  89. // Now we have snapin class id and nodetype guid. Delete them under mmc key.
  90. lRetVal = regTempKey.Open((HKEY) regMMCKey, g_NodeTypes);
  91. ATLASSERT(ERROR_SUCCESS == lRetVal);
  92. if (ERROR_SUCCESS != lRetVal)
  93. continue;
  94. regTempKey.RecurseDeleteKey(szNodeType);
  95. lRetVal = regTempKey.Open((HKEY) regMMCKey, g_SnapIns);
  96. ATLASSERT(ERROR_SUCCESS == lRetVal);
  97. if (ERROR_SUCCESS != lRetVal)
  98. continue;
  99. regTempKey.RecurseDeleteKey(szClsid);
  100. regCLSIDKey.RecurseDeleteKey(szClsid);
  101. // Finally delete the key under enumerator
  102. regVBSnapinsKey.RecurseDeleteKey(szNodeType);
  103. }
  104. } while ( FALSE );
  105. if (bOleInitialized)
  106. CoUninitialize();
  107. return 1;
  108. }