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.

178 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: F O L D R E G . C P P
  7. //
  8. // Contents: Register the folder class
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 30 Sep 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. extern const WCHAR c_szUPnPUIDll[];
  18. extern const TCHAR c_sztUPnPUIDll[];
  19. //---[ Constants ]------------------------------------------------------------
  20. static const TCHAR c_szShellFolderAttributeVal[] = TEXT("Attributes");
  21. static const TCHAR c_szShellFolderKey[] =
  22. TEXT("CLSID\\{e57ce731-33e8-4c51-8354-bb4de9d215d1}\\ShellFolder");
  23. static const TCHAR c_szDelegateFolderKey[] =
  24. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\NetworkNeighborhood\\NameSpace\\DelegateFolders");
  25. static const TCHAR c_szDelegateCLSID[] =
  26. TEXT("{e57ce731-33e8-4c51-8354-bb4de9d215d1}");
  27. static const TCHAR c_szCLSID[] =
  28. TEXT("CLSID");
  29. //---[ Constant globals ]-----------------------------------------------------
  30. //
  31. const WCHAR c_szUPnPUIDll[] = L"upnpui.dll";
  32. const TCHAR c_sztUPnPUIDll[] = TEXT("upnpui.dll");
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Function: HrRegisterFolderClass
  36. //
  37. // Purpose: Fix the registry values for the Shell entries under HKCR,
  38. // CLSID\{CLSID}. The code generated from the RGS script doesn't
  39. // support our replaceable params by default, so we'll fix
  40. // it up after the fact.
  41. //
  42. // Arguments:
  43. // (none)
  44. //
  45. // Returns:
  46. //
  47. // Author: jeffspr 23 Sep 1997
  48. //
  49. // Notes:
  50. //
  51. HRESULT HrRegisterFolderClass()
  52. {
  53. HRESULT hr = S_OK;
  54. LONG lResult = 0;
  55. TCHAR szRegValue[MAX_PATH+1];
  56. TCHAR szWinDir[MAX_PATH+1];
  57. // Adjust the AppID for Local Server or Service
  58. CRegKey keyShellFolder;
  59. if (GetWindowsDirectory(szWinDir, MAX_PATH+1))
  60. {
  61. lResult = keyShellFolder.Open(HKEY_CLASSES_ROOT, c_szShellFolderKey);
  62. if (lResult == ERROR_SUCCESS)
  63. {
  64. DWORD dwFlags = SFGAO_FOLDER;
  65. hr = RegSetValueEx(keyShellFolder,
  66. c_szShellFolderAttributeVal,
  67. 0,
  68. REG_BINARY,
  69. (LPBYTE) &dwFlags,
  70. sizeof (dwFlags));
  71. keyShellFolder.Close();
  72. }
  73. else
  74. {
  75. // Translate LRESULT to HR
  76. //
  77. hr = HRESULT_FROM_WIN32(lResult);
  78. }
  79. }
  80. else // GetWindowsDirectory failed
  81. {
  82. hr = HrFromLastWin32Error();
  83. }
  84. return hr;
  85. }
  86. HRESULT HrUnRegisterUPnPUIKey() {
  87. HRESULT hr = S_OK;
  88. LONG lResult = 0;
  89. TCHAR szWinDir[MAX_PATH+1];
  90. // Adjust the AppID for Local Server or Service
  91. CRegKey keyShellFolder;
  92. if (GetWindowsDirectory(szWinDir, MAX_PATH+1))
  93. {
  94. lResult = keyShellFolder.Open(HKEY_CLASSES_ROOT, c_szCLSID);
  95. if (lResult == ERROR_SUCCESS)
  96. {
  97. lResult = keyShellFolder.RecurseDeleteKey(c_szDelegateCLSID);
  98. if(lResult != ERROR_SUCCESS)
  99. hr = HRESULT_FROM_WIN32(lResult);
  100. keyShellFolder.Close();
  101. }
  102. else
  103. {
  104. // Translate LRESULT to HR
  105. //
  106. hr = HRESULT_FROM_WIN32(lResult);
  107. }
  108. }
  109. else // GetWindowsDirectory failed
  110. {
  111. hr = HrFromLastWin32Error();
  112. }
  113. return hr;
  114. }
  115. HRESULT HrUnRegisterDelegateFolderKey()
  116. {
  117. HRESULT hr = S_OK;
  118. LONG lResult = 0;
  119. TCHAR szWinDir[MAX_PATH+1];
  120. // Adjust the AppID for Local Server or Service
  121. CRegKey keyShellFolder;
  122. if (GetWindowsDirectory(szWinDir, MAX_PATH+1))
  123. {
  124. lResult = keyShellFolder.Open(HKEY_LOCAL_MACHINE, c_szDelegateFolderKey);
  125. if (lResult == ERROR_SUCCESS)
  126. {
  127. hr = keyShellFolder.DeleteSubKey(c_szDelegateCLSID);
  128. keyShellFolder.Close();
  129. }
  130. else
  131. {
  132. // Translate LRESULT to HR
  133. //
  134. hr = HRESULT_FROM_WIN32(lResult);
  135. }
  136. }
  137. else // GetWindowsDirectory failed
  138. {
  139. hr = HrFromLastWin32Error();
  140. }
  141. return hr;
  142. }