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.

140 lines
3.5 KiB

  1. #include "stock.h"
  2. #pragma hdrstop
  3. #include <shellp.h>
  4. #include <dpa.h>
  5. #define CCH_KEYMAX 64 // DOC: max size of a reg key (under shellex)
  6. //===========================================================================
  7. // DCA stuff - Dynamic CLSID array
  8. //
  9. // This is a dynamic array of CLSIDs that you can obtain from
  10. // a registry key or add individually. Use DCA_CreateInstance
  11. // to actually CoCreateInstance the element.
  12. //
  13. //===========================================================================
  14. #ifdef DECLARE_ONCE
  15. HDCA DCA_Create()
  16. {
  17. HDSA hdsa = DSA_Create(sizeof(CLSID), 4);
  18. return (HDCA)hdsa;
  19. }
  20. void DCA_Destroy(HDCA hdca)
  21. {
  22. DSA_Destroy((HDSA)hdca);
  23. }
  24. int DCA_GetItemCount(HDCA hdca)
  25. {
  26. ASSERT(hdca);
  27. return DSA_GetItemCount((HDSA)hdca);
  28. }
  29. const CLSID * DCA_GetItem(HDCA hdca, int i)
  30. {
  31. ASSERT(hdca);
  32. return (const CLSID *)DSA_GetItemPtr((HDSA)hdca, i);
  33. }
  34. BOOL DCA_AddItem(HDCA hdca, REFCLSID rclsid)
  35. {
  36. ASSERT(hdca);
  37. int ccls = DCA_GetItemCount(hdca);
  38. int icls;
  39. for (icls = 0; icls < ccls; icls++)
  40. {
  41. if (IsEqualGUID(rclsid, *DCA_GetItem(hdca,icls)))
  42. return FALSE;
  43. }
  44. DSA_AppendItem((HDSA)hdca, (LPVOID) &rclsid);
  45. return TRUE;
  46. }
  47. HRESULT DCA_CreateInstance(HDCA hdca, int iItem, REFIID riid, void ** ppv)
  48. {
  49. const CLSID * pclsid = DCA_GetItem(hdca, iItem);
  50. return pclsid ? SHCoCreateInstance(NULL, pclsid, NULL, riid, ppv) : E_INVALIDARG;
  51. }
  52. // _KeyIsRestricted (davepl 4-20-99)
  53. //
  54. // Checks to see if there is a user policy in place that disables this key,
  55. //
  56. // For example, in the registry:
  57. //
  58. // CLSID_MyComputer
  59. // +---Shell
  60. // +---Manage
  61. // (Default) = "Mana&ge"
  62. // SuppressionPolicy = REST_NOMANAGEMYCOMPUTERVERB
  63. //
  64. // (Where REST_NOMANAGEMYCOMPUTERVERB is the DWORD value of that particular policy)
  65. //
  66. BOOL _KeyIsRestricted(HKEY hkey)
  67. {
  68. DWORD dwidRest;
  69. DWORD cbdwidRest = sizeof(dwidRest);
  70. if (S_OK == SHGetValue(hkey, NULL, TEXT("SuppressionPolicy"), NULL, &dwidRest, &cbdwidRest))
  71. if (SHRestricted( (RESTRICTIONS)dwidRest) )
  72. return TRUE;
  73. return FALSE;
  74. }
  75. #endif // DECLARE_ONCE
  76. BOOL _KeyIsRestricted(HKEY hkey);
  77. void DCA_AddItemsFromKey(HDCA hdca, HKEY hkey, LPCTSTR pszSubKey)
  78. {
  79. HKEY hkEnum;
  80. if (RegOpenKeyEx(hkey, pszSubKey, 0L, KEY_READ, &hkEnum) == ERROR_SUCCESS)
  81. {
  82. TCHAR sz[CCH_KEYMAX];
  83. for (int i = 0; RegEnumKey(hkEnum, i, sz, ARRAYSIZE(sz)) == ERROR_SUCCESS; i++)
  84. {
  85. HKEY hkEach;
  86. if (RegOpenKeyEx(hkEnum, sz, 0L, KEY_READ, &hkEach) == ERROR_SUCCESS)
  87. {
  88. if (!_KeyIsRestricted(hkEach))
  89. {
  90. CLSID clsid;
  91. // First, check if the key itself is a CLSID
  92. BOOL fAdd = GUIDFromString(sz, &clsid);
  93. if (!fAdd)
  94. {
  95. LONG cb = sizeof(sz);
  96. if (RegQueryValue(hkEach, NULL, sz, &cb) == ERROR_SUCCESS)
  97. {
  98. fAdd = GUIDFromString(sz, &clsid);
  99. }
  100. }
  101. // Add the CLSID if we successfully got the CLSID.
  102. if (fAdd)
  103. {
  104. DCA_AddItem(hdca, clsid);
  105. }
  106. }
  107. RegCloseKey(hkEach);
  108. }
  109. }
  110. RegCloseKey(hkEnum);
  111. }
  112. }