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.

306 lines
11 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. oemfolder.c
  5. Abstract:
  6. Create registry entries that identify the OEM folder using the data from WINBOM.INI file.
  7. Author:
  8. Sankar Ramasubramanian 11/21/2000
  9. Revision History:
  10. Sankar 3/23/2001: Added support for Oem Branding link and Desktop Shortcuts folder.
  11. --*/
  12. #include "factoryp.h"
  13. const TCHAR c_szOemBrandLinkText[] = _T("OemBrandLinkText");
  14. const TCHAR c_szOemBrandLinkInfotip[] = _T("OemBrandLinkInfotip");
  15. const TCHAR c_szOemBrandIcon[] = _T("OemBrandIcon");
  16. const TCHAR c_szOemBrandLink[] = _T("OemBrandLink");
  17. const TCHAR c_szDesktopShortcutsFolderName[]= _T("DesktopShortcutsFolderName");
  18. const TCHAR c_szOemStartMenuData[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\OemStartMenuData");
  19. const TCHAR c_szRegCLSIDKey[] = _T("CLSID\\{2559a1f6-21d7-11d4-bdaf-00c04f60b9f0}");
  20. const TCHAR c_szSubKeyPropBag[] = _T("Instance\\InitPropertyBag");
  21. const TCHAR c_szSubKeyDefIcon[] = _T("DefaultIcon");
  22. const TCHAR c_szValNameInfoTip[] = _T("InfoTip");
  23. const TCHAR c_szValNameParam1[] = _T("Param1");
  24. const TCHAR c_szValNameCommand[] = _T("Command");
  25. const TCHAR c_szRegShowOemLinkKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartMenu\\StartPanel\\ShowOEMLink");
  26. const TCHAR c_szValNoOemLink[] = _T("NoOEMLinkInstalled");
  27. #define STR_0 _T("0")
  28. typedef struct {
  29. LPCTSTR pszSectionName; // Section Name in WinBom.ini file.
  30. LPCTSTR pszIniKeyName; // Key name under the section in WinBom.ini file.
  31. HKEY hkRoot; // HKEY_CLASSES_ROOT or HKEY_LOCAL_MACHINE
  32. LPCTSTR pszRegKey; // Reg Key value.
  33. LPCTSTR pszSubKey; // Subkey in registry.
  34. LPCTSTR pszRegValueName; // Value name under which it is saved in registry.
  35. DWORD dwValueType; // Registry Value type.
  36. BOOL fExpandSz; // Should we expand the string for environment variables?
  37. LPCTSTR pszLogFileText; // Information for the logfile.
  38. } OEM_STARTMENU_DATA;
  39. //
  40. // The following OemInfo[] table contains all the registry key, sub-key, value-name information
  41. // for a given oem data.
  42. //
  43. OEM_STARTMENU_DATA OemInfo[] = {
  44. { WBOM_OEMLINK_SECTION,
  45. c_szOemBrandLinkText,
  46. HKEY_CLASSES_ROOT,
  47. c_szRegCLSIDKey,
  48. NULL,
  49. NULL,
  50. REG_SZ,
  51. FALSE,
  52. _T("Oem Link's Text")
  53. },
  54. { WBOM_OEMLINK_SECTION,
  55. c_szOemBrandLinkText,
  56. HKEY_CLASSES_ROOT,
  57. c_szRegCLSIDKey,
  58. c_szSubKeyPropBag,
  59. c_szValNameCommand,
  60. REG_SZ,
  61. FALSE,
  62. _T("Oem Link's Default Command")
  63. },
  64. { WBOM_OEMLINK_SECTION,
  65. c_szOemBrandLinkInfotip,
  66. HKEY_CLASSES_ROOT,
  67. c_szRegCLSIDKey,
  68. NULL,
  69. c_szValNameInfoTip,
  70. REG_SZ,
  71. FALSE,
  72. _T("Oem Link's InfoTip text")
  73. },
  74. { WBOM_OEMLINK_SECTION,
  75. c_szOemBrandIcon,
  76. HKEY_CLASSES_ROOT,
  77. c_szRegCLSIDKey,
  78. c_szSubKeyDefIcon,
  79. NULL,
  80. REG_EXPAND_SZ,
  81. TRUE,
  82. _T("Oem Link's Icon path")
  83. },
  84. { WBOM_OEMLINK_SECTION,
  85. c_szOemBrandLink,
  86. HKEY_CLASSES_ROOT,
  87. c_szRegCLSIDKey,
  88. c_szSubKeyPropBag,
  89. c_szValNameParam1,
  90. REG_SZ,
  91. TRUE,
  92. _T("Oem Link's path to HTM file")
  93. },
  94. { WBOM_DESKFLDR_SECTION,
  95. c_szDesktopShortcutsFolderName,
  96. HKEY_LOCAL_MACHINE,
  97. c_szOemStartMenuData,
  98. NULL,
  99. c_szDesktopShortcutsFolderName,
  100. REG_SZ,
  101. FALSE,
  102. _T("Desktop shortcuts cleanup Folder name")
  103. }
  104. };
  105. //
  106. // Given an index into OemInfo[] table and the data, this function updates the proper registry
  107. // with the given data.
  108. //
  109. BOOL ProcessOemEntry(HKEY hOemDataKey, int iIndex, LPTSTR pszOemData)
  110. {
  111. HKEY hkSubKey = NULL;
  112. BOOL fSubKeyOpened = FALSE;
  113. BOOL fOemEntryEntered = FALSE;
  114. //See if we need to open a subkey under the given key.
  115. if(OemInfo[iIndex].pszSubKey)
  116. {
  117. //if so open the sub-key.
  118. if(ERROR_SUCCESS == RegCreateKeyEx(hOemDataKey,
  119. OemInfo[iIndex].pszSubKey,
  120. 0,
  121. NULL,
  122. REG_OPTION_NON_VOLATILE,
  123. KEY_READ | KEY_WRITE,
  124. NULL,
  125. &hkSubKey,
  126. NULL))
  127. {
  128. fSubKeyOpened = TRUE; //Remember to close this sub-key before we return.
  129. }
  130. else
  131. hkSubKey = NULL;
  132. }
  133. else
  134. hkSubKey = hOemDataKey;
  135. if(*pszOemData == NULLCHR)
  136. {
  137. // BUG#441349: Sometimes factory.exe gets confused and runs with
  138. // a blank WINBOM.INI. So don't treat the absence of OEM data as
  139. // a cue to remove the OEM Link; otherwise we end up uninstalling
  140. // what got successfully installed by the previous factory run...
  141. fOemEntryEntered = FALSE; //No OEM data (this time)
  142. }
  143. else
  144. {
  145. LPTSTR psz;
  146. TCHAR szLocalStr[MAX_PATH+1];
  147. psz = pszOemData;
  148. // Check if we need to expand the value for environment variables!
  149. if(OemInfo[iIndex].fExpandSz)
  150. {
  151. if(ExpandEnvironmentStrings((LPCTSTR)pszOemData, szLocalStr, ARRAYSIZE(szLocalStr)))
  152. psz = szLocalStr;
  153. }
  154. //Set the value of the "OEM Link" value.
  155. if ( (hkSubKey == NULL) ||
  156. (ERROR_SUCCESS != RegSetValueEx(hkSubKey,
  157. OemInfo[iIndex].pszRegValueName,
  158. 0,
  159. OemInfo[iIndex].dwValueType,
  160. (LPBYTE) (psz),
  161. (lstrlen(psz)+1) * sizeof(TCHAR))))
  162. {
  163. fOemEntryEntered = FALSE; //Error adding the entry!
  164. FacLogFile(0 | LOG_ERR, IDS_ERR_SET_OEMDATA, OemInfo[iIndex].pszLogFileText, psz);
  165. }
  166. else
  167. {
  168. fOemEntryEntered = TRUE;
  169. FacLogFile(2, IDS_SUCCESS_OEMDATA, OemInfo[iIndex].pszLogFileText, psz);
  170. }
  171. }
  172. if(fSubKeyOpened) // If we opened the sub-key earlier,....
  173. RegCloseKey(hkSubKey); //... better close it before we return!
  174. return(fOemEntryEntered); //Return Successfully entered or deleted the entry!
  175. }
  176. //
  177. // This function creates the registry entries that specifies the Oem Link and the
  178. // Desktop Shortcuts Folder name.
  179. //
  180. BOOL OemData(LPSTATEDATA lpStateData)
  181. {
  182. LPTSTR lpszWinBOMPath = lpStateData->lpszWinBOMPath;
  183. HKEY hOemDataKey;
  184. int iIndex;
  185. BOOL fEnableOemLink = FALSE; //By default disable it!
  186. for(iIndex = 0; iIndex < ARRAYSIZE(OemInfo); iIndex++)
  187. {
  188. //Open the key under HKLM
  189. if (ERROR_SUCCESS == RegCreateKeyEx(OemInfo[iIndex].hkRoot,
  190. OemInfo[iIndex].pszRegKey,
  191. 0,
  192. NULL,
  193. REG_OPTION_NON_VOLATILE,
  194. KEY_READ | KEY_WRITE,
  195. NULL,
  196. &hOemDataKey,
  197. NULL))
  198. {
  199. TCHAR szOemData[MAX_PATH];
  200. BOOL fSuccess = FALSE;
  201. szOemData[0] = NULLCHR;
  202. GetPrivateProfileString(OemInfo[iIndex].pszSectionName,
  203. OemInfo[iIndex].pszIniKeyName,
  204. NULLSTR,
  205. szOemData, AS(szOemData), lpszWinBOMPath);
  206. fSuccess = ProcessOemEntry(hOemDataKey, iIndex, &szOemData[0]);
  207. //If we successfully added the "Command" for the OEM link, then ...
  208. if(fSuccess && (lstrcmpi(OemInfo[iIndex].pszRegValueName, c_szValNameCommand) == 0))
  209. {
  210. //..We should enable the link in the registry!
  211. fEnableOemLink = TRUE;
  212. }
  213. RegCloseKey(hOemDataKey);
  214. }
  215. }
  216. // We enable the OEM link in the registry, only if we could successfully add the OemLink data
  217. // earlier.
  218. if(fEnableOemLink)
  219. {
  220. HKEY hKey;
  221. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  222. c_szRegShowOemLinkKey,
  223. 0,
  224. NULL,
  225. REG_OPTION_NON_VOLATILE,
  226. KEY_READ | KEY_WRITE,
  227. NULL,
  228. &hKey,
  229. NULL))
  230. {
  231. DWORD dwNoOemLink = 0; //Writing '0' to "NoOemLinkInstalled" will enable this!
  232. if(ERROR_SUCCESS != RegSetValueEx(hKey, c_szValNoOemLink, 0, REG_DWORD, (LPBYTE)(&dwNoOemLink), sizeof(dwNoOemLink)))
  233. {
  234. FacLogFile(0 | LOG_ERR, IDS_ERR_SET_OEMDATA, c_szValNoOemLink, STR_0);
  235. }
  236. else
  237. {
  238. FacLogFile(2, IDS_SUCCESS_OEMDATA, c_szValNoOemLink, STR_0);
  239. }
  240. RegCloseKey(hKey);
  241. // Now tell the Start Menu to pick up the new OEM link
  242. NotifyStartMenu(TMFACTORY_OEMLINK);
  243. }
  244. }
  245. return TRUE;
  246. }
  247. BOOL DisplayOemData(LPSTATEDATA lpStateData)
  248. {
  249. int iIndex;
  250. BOOL bRet = FALSE;
  251. for( iIndex = 0; ( iIndex < AS(OemInfo) ) && !bRet; iIndex++ )
  252. {
  253. if ( IniSettingExists(lpStateData->lpszWinBOMPath, OemInfo[iIndex].pszSectionName, OemInfo[iIndex].pszIniKeyName, NULL) )
  254. {
  255. bRet = TRUE;
  256. }
  257. }
  258. return bRet;
  259. }
  260. #define TM_FACTORY (WM_USER+0x103)
  261. void NotifyStartMenu(UINT code)
  262. {
  263. HWND hwnd = FindWindow(TEXT("Shell_TrayWnd"), NULL);
  264. if (hwnd) {
  265. SendMessage(hwnd, TM_FACTORY, code, 0);
  266. }
  267. }