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.

137 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Canvas6.cpp
  5. Abstract:
  6. This app. deletes HKEY\CLASSES_ROOT \ .HTC key during uninstall. This
  7. breaks the ControlPanel -> Add/Remove programs
  8. Notes:
  9. This is specific to this app.
  10. History:
  11. 11/17/2000 prashkud Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(Canvas6)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(RegOpenKeyA)
  18. APIHOOK_ENUM_ENTRY(RegCloseKey)
  19. APIHOOK_ENUM_ENTRY(RegDeleteKeyA)
  20. APIHOOK_ENUM_END
  21. HKEY g_hOpenKey = 0;
  22. /*++
  23. Store the key for .htc
  24. --*/
  25. LONG
  26. APIHOOK(RegOpenKeyA)(
  27. HKEY hkey,
  28. LPCSTR lpSubKey,
  29. PHKEY phkResult)
  30. {
  31. LONG lRet = 0;
  32. lRet = ORIGINAL_API(RegOpenKeyA)(hkey,lpSubKey,phkResult);
  33. if ((hkey == HKEY_CLASSES_ROOT)
  34. && lpSubKey
  35. && (lstrcmpiA((const char*) lpSubKey,".htc") == 0))
  36. {
  37. if (phkResult)
  38. {
  39. g_hOpenKey = *(phkResult);
  40. }
  41. }
  42. return lRet;
  43. }
  44. /*++
  45. Ignore the close if required.
  46. --*/
  47. LONG
  48. APIHOOK(RegCloseKey)(
  49. HKEY hkey)
  50. {
  51. if (g_hOpenKey && (g_hOpenKey == hkey))
  52. {
  53. return ERROR_SUCCESS;
  54. }
  55. else
  56. {
  57. return (ORIGINAL_API(RegCloseKey)(hkey));
  58. }
  59. }
  60. /*++
  61. Ignore the delete.
  62. --*/
  63. LONG
  64. APIHOOK(RegDeleteKeyA)(
  65. HKEY hkey,
  66. LPCSTR lpSubKey)
  67. {
  68. LONG lRet = 0;
  69. if ((hkey == HKEY_CLASSES_ROOT)
  70. && lpSubKey
  71. && (lstrcmpiA((const char*)lpSubKey,".htc") == 0))
  72. {
  73. if (g_hOpenKey)
  74. {
  75. if(RegDeleteValueA(g_hOpenKey,NULL))
  76. {
  77. // Add DPF to indicate an error during deletion of the value installed by the app.
  78. DPFN( eDbgLevelError,
  79. "Could not delete the value in the key= \"%s\".", lpSubKey);
  80. }
  81. RegCloseKey(g_hOpenKey);
  82. g_hOpenKey = 0;
  83. }
  84. lRet = ERROR_SUCCESS;
  85. }
  86. else
  87. {
  88. lRet = ORIGINAL_API(RegDeleteKeyA)(hkey,lpSubKey);
  89. }
  90. return lRet;
  91. }
  92. /*++
  93. Register hooked functions
  94. --*/
  95. HOOK_BEGIN
  96. APIHOOK_ENTRY(ADVAPI32.DLL, RegOpenKeyA)
  97. APIHOOK_ENTRY(ADVAPI32.DLL, RegCloseKey)
  98. APIHOOK_ENTRY(ADVAPI32.DLL, RegDeleteKeyA)
  99. HOOK_END
  100. IMPLEMENT_SHIM_END