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.

242 lines
12 KiB

  1. #include "stdafx.h"
  2. #include <LMCONS.H> // 97/07/22 vtan: for UNLEN
  3. #pragma hdrstop
  4. BOOL OnUpgradeDisableActiveDesktopFeatures();
  5. void CreateMyCurHomeComponent(BOOL fChecked)
  6. {
  7. // If there is a policy to prevent adding desktop components, then we should not attempt to add.
  8. // Otherwise, a new user gets an error message when they login for the first time.
  9. // Bug #21300 -- Fixed on 2/28/2001 -- Sankar
  10. if (SHRestricted(REST_NOADDDESKCOMP))
  11. return;
  12. //Add the base components!
  13. TCHAR szBuf[MAX_PATH];
  14. ISubscriptionMgr * psm;
  15. // Add a component that points to "about:home"
  16. LoadString(HINST_THISDLL, IDS_MY_CURRENT_HOMEPAGE, szBuf, ARRAYSIZE(szBuf));
  17. // 98/07/14 vtan #176721: Changed the following to pass default component
  18. // positions to AddRemoveDesktopComponentNoUI so that the restored position may
  19. // be set to the default component position.
  20. // int iTop, iLeft;
  21. // DWORD dwWidth, dwHeight;
  22. // GetMyCurHomePageStartPos(&iLeft, &iTop, &dwWidth, &dwHeight);
  23. // AddRemoveDesktopComponentNoUI(TRUE, AD_APPLY_SAVE, MY_HOMEPAGE_SOURCE, szBuf, COMP_TYPE_WEBSITE, iLeft, iTop, dwWidth, dwHeight, TRUE, IS_SPLIT);
  24. AddRemoveDesktopComponentNoUI(TRUE, AD_APPLY_SAVE, MY_HOMEPAGE_SOURCE, szBuf, COMP_TYPE_WEBSITE, COMPONENT_DEFAULT_LEFT, COMPONENT_DEFAULT_TOP, COMPONENT_DEFAULT_WIDTH, COMPONENT_DEFAULT_HEIGHT, fChecked, IS_SPLIT);
  25. if (SUCCEEDED(CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  26. CLSCTX_INPROC_SERVER, IID_ISubscriptionMgr, (void**)&psm)))
  27. {
  28. WCHAR wszName[MAX_PATH];
  29. //We need to zero init this structure except the cbSize field.
  30. SUBSCRIPTIONINFO siDefault = {sizeof(SUBSCRIPTIONINFO)};
  31. SHTCharToUnicode(szBuf, wszName, ARRAYSIZE(wszName));
  32. //This field is already initialized above.
  33. //siDefault.cbSize = sizeof(siDefault);
  34. psm->CreateSubscription(NULL, MY_HOMEPAGE_SOURCEW, wszName, CREATESUBS_NOUI, SUBSTYPE_DESKTOPURL, &siDefault);
  35. psm->Release();
  36. }
  37. }
  38. STDAPI CDeskHtmlProp_RegUnReg(BOOL bReg)
  39. {
  40. HKEY hKey;
  41. DWORD userNameSize;
  42. TCHAR lpszDeskcomp[MAX_PATH];
  43. TCHAR userName[UNLEN];
  44. // 98/07/22 vtan #202707: Problem: This code gets called for the first time when NT
  45. // runs. This sets up the default user profile. Anything that is added to this profile
  46. // is propagated to any current user when upgrading from NT 4.0 to NT 5.0. This
  47. // causes the DeskHtmlVersion, DeskHtmlMinorVersion and Component\0 to be replaced
  48. // with the default component. By replacing the version registry entries any old
  49. // components will not get correctly upgraded by the component reading code. It also
  50. // destroys the first component.
  51. // Solution: Prevent a default component being added at setup time by checking the
  52. // logged on user is "SYSTEM". If the user is anybody other than system then perform
  53. // the update or addition of the default component.
  54. userNameSize = ARRAYSIZE(userName);
  55. if ((GetUserName(userName, &userNameSize) != 0) && (lstrcmp(userName, TEXT("SYSTEM")) == 0))
  56. return(S_OK); // an ungracious exit right here and now!
  57. if(bReg)
  58. {
  59. DWORD dwDisposition;
  60. DWORD dwDeskHtmlVersion = 0;
  61. DWORD dwDeskHtmlMinorVersion = 0;
  62. DWORD dwType;
  63. GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_COMPONENTS, NULL);
  64. if(RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp,
  65. 0, NULL, 0, KEY_CREATE_SUB_KEY|KEY_QUERY_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  66. {
  67. //Get the version stamp from the registry
  68. if(dwDisposition == REG_OPENED_EXISTING_KEY)
  69. {
  70. DWORD dwDataLength = SIZEOF(DWORD);
  71. SHQueryValueEx(hKey, REG_VAL_COMP_VERSION, NULL, &dwType, (LPBYTE)(&dwDeskHtmlVersion), &dwDataLength);
  72. SHQueryValueEx(hKey, REG_VAL_COMP_MINOR_VERSION, NULL, &dwType, (LPBYTE)(&dwDeskHtmlMinorVersion), &dwDataLength);
  73. }
  74. //We need to close this key before we delete it
  75. RegCloseKey(hKey);
  76. // If this branch is already there, don't set default comp.
  77. // Note: The differences between IE4_DESKHTML_VERSION and CUR_DESKHTML_VERSION are
  78. // automatically taken care of when we read the components. So, we need to check only
  79. // for very old versions here.
  80. if (dwDeskHtmlVersion < IE4_DESKHTML_VERSION)
  81. {
  82. //Delete the existing components.
  83. SHDeleteKey(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp);
  84. // Create the default active desktop configuration
  85. if(RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp, 0, NULL, 0,
  86. (KEY_CREATE_SUB_KEY | KEY_SET_VALUE), NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  87. {
  88. //We need an initial state
  89. DWORD dw;
  90. dw = CUR_DESKHTML_VERSION;
  91. RegSetValueEx(hKey, REG_VAL_COMP_VERSION, 0, REG_DWORD, (LPBYTE)&dw, SIZEOF(dw));
  92. dw = CUR_DESKHTML_MINOR_VERSION;
  93. RegSetValueEx(hKey, REG_VAL_COMP_MINOR_VERSION, 0, REG_DWORD, (LPBYTE)&dw, SIZEOF(dw));
  94. dw = COMPSETTING_ENABLE;
  95. RegSetValueEx(hKey, REG_VAL_COMP_SETTINGS, 0, REG_DWORD, (LPBYTE)&dw, SIZEOF(dw));
  96. //Add the home page component
  97. CreateMyCurHomeComponent(FALSE); //For millennium we want to disable the component.
  98. RegCloseKey(hKey);
  99. }
  100. // Create the default active desktop safemode configuration
  101. if(RegCreateKeyEx(HKEY_CURRENT_USER, REG_DESKCOMP_SAFEMODE,
  102. 0, NULL, 0, KEY_CREATE_SUB_KEY, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  103. {
  104. DWORD dwDisposition;
  105. HKEY hKey2;
  106. if(RegCreateKeyEx(hKey, REG_DESKCOMP_GENERAL_SUFFIX, 0, NULL, 0,
  107. (KEY_CREATE_SUB_KEY | KEY_SET_VALUE), NULL, &hKey2, &dwDisposition) == ERROR_SUCCESS)
  108. {
  109. TCHAR szSafeMode[MAX_PATH];
  110. GetWindowsDirectory(szSafeMode, ARRAYSIZE(szSafeMode));
  111. lstrcat(szSafeMode, DESKTOPHTML_DEFAULT_SAFEMODE);
  112. // Show safemode.htx
  113. SHRegSetPath(hKey2, NULL, REG_VAL_GENERAL_WALLPAPER, szSafeMode, 0);
  114. // Don't bring up the gallery dialog box
  115. dwDisposition = 0;
  116. RegSetValueEx(hKey2, REG_VAL_GENERAL_VISITGALLERY, 0, REG_DWORD, (LPBYTE)&dwDisposition, sizeof(dwDisposition));
  117. RegCloseKey(hKey2);
  118. }
  119. RegCloseKey(hKey);
  120. }
  121. // Create the default scheme key
  122. if(RegCreateKeyEx(HKEY_CURRENT_USER, REG_DESKCOMP_SCHEME, 0, NULL, 0,
  123. (KEY_CREATE_SUB_KEY | KEY_SET_VALUE), NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  124. {
  125. RegSetValueEx(hKey, REG_VAL_SCHEME_EDIT, 0, REG_SZ, (LPBYTE)TEXT(""), SIZEOF(TCHAR));
  126. RegSetValueEx(hKey, REG_VAL_SCHEME_DISPLAY, 0, REG_SZ, (LPBYTE)TEXT(""), SIZEOF(TCHAR));
  127. RegCloseKey(hKey);
  128. }
  129. // Set the components to be dirty sothat we re-generate desktop.htm
  130. // the first boot after installing IE4.0.
  131. SetDesktopFlags(COMPONENTS_DIRTY, COMPONENTS_DIRTY);
  132. GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_GENERAL, NULL);
  133. RegCreateKeyEx(HKEY_CURRENT_USER, lpszDeskcomp,
  134. 0, NULL, 0, KEY_CREATE_SUB_KEY, NULL, &hKey, &dwDisposition);
  135. RegCloseKey(hKey);
  136. }
  137. else
  138. {
  139. //See if we are upgrading from an older version like IE4.
  140. if (dwDeskHtmlVersion < CUR_DESKHTML_VERSION)
  141. {
  142. // If so, save the DESKHTML_VERSION we are upgrading from.
  143. // We use this later in SHGetSetSettings to decide if active desktop is ON/OFF.
  144. // NOTE: The "UpgradedFrom" value is at "...\Desktop" and NOT at "..\Desktop\Components"
  145. // This is because the "Components" key gets destroyed very often.
  146. SHSetValue(HKEY_CURRENT_USER, REG_DESKCOMP, REG_VAL_COMP_UPGRADED_FROM,
  147. REG_DWORD, (LPBYTE)&dwDeskHtmlVersion, SIZEOF(dwDeskHtmlVersion));
  148. }
  149. // The major version numbers match. So check if the minor version numbers
  150. // match too!
  151. if(dwDeskHtmlMinorVersion < CUR_DESKHTML_MINOR_VERSION)
  152. {
  153. //Update the new Minor version number!
  154. if(RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp, 0, NULL, 0,
  155. (KEY_CREATE_SUB_KEY | KEY_SET_VALUE), NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  156. {
  157. DWORD dw;
  158. dw = CUR_DESKHTML_MINOR_VERSION;
  159. RegSetValueEx(hKey, REG_VAL_COMP_MINOR_VERSION, 0, REG_DWORD, (LPBYTE)&dw, SIZEOF(dw));
  160. RegCloseKey(hKey);
  161. }
  162. // Add the new home page component
  163. if((dwDeskHtmlVersion <= 0x10f) && (dwDeskHtmlMinorVersion <= 0x0001))
  164. CreateMyCurHomeComponent(FALSE);
  165. //
  166. // If this is an upgrade from W2K or earlier, we need to check if the
  167. // active desktop is OFF. If so, we need to turn off all the desktop components
  168. // sothat the active desktop continues to be OFF.
  169. if((dwDeskHtmlVersion <= NT5_DESKHTML_VERSION) &&
  170. (dwDeskHtmlMinorVersion <= NT5_DESKHTML_MINOR_VERSION))
  171. {
  172. OnUpgradeDisableActiveDesktopFeatures();
  173. }
  174. // Minor version numbers do not match. So, set the dirty bit to force
  175. // the regeneration of desktop.htt later when needed.
  176. SetDesktopFlags(COMPONENTS_DIRTY, COMPONENTS_DIRTY);
  177. // 98/07/16 vtan #176721/#202707: Added the following code to delete HKCU\Software\
  178. // Microsoft\Internet Explorer\Desktop\General\ComponentsPositioned because in NT 4.0
  179. // with IE 4.0 SP1 this registry entry is incorrectly incremented when the components
  180. // are iterated rather than when they are positioned. This resets the counter
  181. // in NT 5.0 where the bug has been fixed.
  182. GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_GENERAL, NULL);
  183. DWORD dw;
  184. if (RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hKey, &dw) == ERROR_SUCCESS)
  185. {
  186. (LONG)RegDeleteValue(hKey, REG_VAL_GENERAL_CCOMPPOS);
  187. (LONG)RegCloseKey(hKey);
  188. }
  189. }
  190. }
  191. }
  192. }
  193. else
  194. {
  195. SHDeleteKey(HKEY_LOCAL_MACHINE, c_szRegDeskHtmlProp);
  196. SHDeleteKey(HKEY_CURRENT_USER, REG_DESKCOMP_COMPONENTS_ROOT);
  197. SHDeleteKey(HKEY_CURRENT_USER, REG_DESKCOMP_GENERAL_ROOT);
  198. SHDeleteKey(HKEY_CURRENT_USER, REG_DESKCOMP_SAFEMODE);
  199. SHDeleteKey(HKEY_CURRENT_USER, REG_DESKCOMP_SCHEME);
  200. }
  201. return S_OK;
  202. }