Leaked source code of windows server 2003
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.

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