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.

329 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Works99.cpp
  5. Abstract:
  6. This shim is to add in the missing/corrupted registry values
  7. for Works Suite 99 / Works Deluxe 99
  8. Notes:
  9. This is a app specific shim.
  10. History:
  11. 03/12/2001 rankala Created
  12. 03/12/2001 a-leelat Modified for shim.
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(Works99)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_END
  19. static LONG SetThreadingModel2Both(IN WCHAR *szKeyPath);
  20. static LONG AddCAGKey(void);
  21. VOID Works99()
  22. {
  23. // Fix broken ThreadingModel value for several CLSID
  24. SetThreadingModel2Both(L"CLSID\\{29D44CA0-DD3A-11d0-95DF-00C04FD57E8C}\\InProcServer32");
  25. SetThreadingModel2Both(L"CLSID\\{4BA2C080-68BB-11d0-95BD-00C04FD57E8C}\\InProcServer32");
  26. SetThreadingModel2Both(L"CLSID\\{4BA2C081-68BB-11d0-95BD-00C04FD57E8C}\\InProcServer32");
  27. SetThreadingModel2Both(L"CLSID\\{56EE2738-BDF7-11d1-8C28-00C04FB995C9}\\InProcServer32");
  28. SetThreadingModel2Both(L"CLSID\\{6CFFE322-6E97-11d1-8C1C-00C04FB995C9}\\InProcServer32");
  29. SetThreadingModel2Both(L"CLSID\\{711D9B80-02F2-11d1-B244-00AA00A74BFF}\\InProcServer32");
  30. SetThreadingModel2Both(L"CLSID\\{8EE20D86-6DEC-11d1-8C1C-00C04FB995C9}\\InProcServer32");
  31. SetThreadingModel2Both(L"CLSID\\{92AABF20-39C8-11d1-95F6-00C04FD57E8C}\\InProcServer32");
  32. SetThreadingModel2Both(L"CLSID\\{9B3B23C0-E236-11d0-A5C9-0080C7195D7E}\\InProcServer32");
  33. SetThreadingModel2Both(L"CLSID\\{9B3B23C1-E236-11d0-A5C9-0080C7195D7E}\\InProcServer32");
  34. SetThreadingModel2Both(L"CLSID\\{9B3B23C2-E236-11d0-A5C9-0080C7195D7E}\\LocalServer32");
  35. SetThreadingModel2Both(L"CLSID\\{9B3B23C3-E236-11d0-A5C9-0080C7195D7E}\\InProcServer32");
  36. SetThreadingModel2Both(L"CLSID\\{CB40F470-02F1-11D1-B244-00AA00A74BFF}\\InProcServer32");
  37. SetThreadingModel2Both(L"CLSID\\{EAF6F280-DD53-11d0-95DF-00C04FD57E8C}\\InProcServer32");
  38. // Add CAG key and all of its values if missing
  39. AddCAGKey();
  40. }
  41. /*
  42. Function Description:
  43. Set ThreadingModel Registry REG_SZ value to "Both" for a given key
  44. */
  45. static
  46. LONG SetThreadingModel2Both(
  47. IN WCHAR *szKeyPath
  48. )
  49. {
  50. HKEY hKey;
  51. LONG lStatus;
  52. // Fix broken ThreadingModel value for several CLSID
  53. lStatus = RegOpenKeyExW (HKEY_CLASSES_ROOT,
  54. szKeyPath,
  55. 0,
  56. KEY_ALL_ACCESS,
  57. &hKey);
  58. if ( lStatus == ERROR_SUCCESS ) {
  59. // Set it always since this is a one-time operation and
  60. //it must have "Both", no matter what is the current data
  61. lStatus = RegSetValueExW(hKey,
  62. L"ThreadingModel",
  63. 0,
  64. REG_SZ,
  65. (BYTE*)L"Both",
  66. (wcslen(L"Both") + 1) * sizeof(WCHAR));
  67. RegCloseKey(hKey);
  68. }
  69. return lStatus;
  70. }
  71. /*
  72. Function Description:
  73. Check existance of CAG key, add key + all values if it doesn't exist
  74. */
  75. static
  76. LONG AddCAGKey(
  77. void
  78. )
  79. {
  80. HKEY hKey, hKey1, hKey2;
  81. WCHAR szData[MAX_PATH];
  82. DWORD dwData;
  83. LONG lStatus;
  84. DWORD dwCreated;
  85. // If this key doesn't exist, assume that something
  86. // is completely wrong and don't try to complete the Registry
  87. lStatus = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
  88. L"SOFTWARE\\Microsoft\\ClipArt Gallery\\5.0\\ConcurrentDatabases",
  89. 0,
  90. KEY_ALL_ACCESS,
  91. &hKey);
  92. if (ERROR_SUCCESS != lStatus) {
  93. return lStatus;
  94. }
  95. // Check for next sub key, create if missing
  96. lStatus = RegCreateKeyExW (hKey,
  97. L"Core",
  98. 0,
  99. NULL,
  100. REG_OPTION_NON_VOLATILE,
  101. KEY_ALL_ACCESS,
  102. NULL,
  103. &hKey1,
  104. NULL);
  105. RegCloseKey(hKey);
  106. if (ERROR_SUCCESS != lStatus) {
  107. return lStatus;
  108. }
  109. // Check for next sub key, create if missing,
  110. // if so, we need create a set of values as well
  111. lStatus = RegCreateKeyExW (hKey1,
  112. L"CAG",
  113. 0,
  114. NULL,
  115. REG_OPTION_NON_VOLATILE,
  116. KEY_ALL_ACCESS,
  117. NULL,
  118. &hKey2,
  119. &dwCreated);
  120. RegCloseKey(hKey1);
  121. if (ERROR_SUCCESS != lStatus) {
  122. return lStatus;
  123. }
  124. if (REG_CREATED_NEW_KEY == dwCreated) {
  125. // Create the appropriate set of values
  126. if (! SHGetSpecialFolderPathW(NULL, szData, CSIDL_PROGRAM_FILES, FALSE)) {
  127. RegCloseKey(hKey2);
  128. return ERROR_FILE_NOT_FOUND;
  129. }
  130. if (!SUCCEEDED(StringCchCatW(szData, ARRAYSIZE(szData), L"\\Common Files\\Microsoft Shared\\Clipart\\cagcat50")))
  131. {
  132. RegCloseKey(hKey2);
  133. return ERROR_FILE_NOT_FOUND;
  134. }
  135. lStatus = RegSetValueExW(hKey2,
  136. L"Section1Path1",
  137. 0,
  138. REG_SZ,
  139. (BYTE*)szData,
  140. (wcslen(szData) + 1) * sizeof(WCHAR));
  141. if (ERROR_SUCCESS != lStatus) {
  142. RegCloseKey(hKey2);
  143. return lStatus;
  144. }
  145. StringCchCatW(szData, ARRAYSIZE(szData), L"\\CagCat50.MMC");
  146. lStatus = RegSetValueExW(hKey2,
  147. L"CatalogPath0",
  148. 0,
  149. REG_SZ,
  150. (BYTE*)szData,
  151. (wcslen(szData) + 1) * sizeof(WCHAR));
  152. if (ERROR_SUCCESS != lStatus) {
  153. RegCloseKey(hKey2);
  154. return lStatus;
  155. }
  156. dwData = 3;
  157. lStatus = RegSetValueExW(hKey2,
  158. L"CatalogDriveType0",
  159. 0,
  160. REG_DWORD,
  161. (BYTE*)&dwData,
  162. sizeof(DWORD));
  163. if (ERROR_SUCCESS != lStatus) {
  164. RegCloseKey(hKey2);
  165. return lStatus;
  166. }
  167. dwData = 1;
  168. lStatus = RegSetValueExW(hKey2,
  169. L"CatalogSections",
  170. 0,
  171. REG_DWORD,
  172. (BYTE*)&dwData,
  173. sizeof(DWORD));
  174. if (ERROR_SUCCESS != lStatus) {
  175. RegCloseKey(hKey2);
  176. return lStatus;
  177. }
  178. StringCchCopyW(szData, ARRAYSIZE(szData), L"MAIN");
  179. lStatus = RegSetValueExW(hKey2,
  180. L"Section1Name",
  181. 0,
  182. REG_SZ,
  183. (BYTE*)szData,
  184. (wcslen(szData) + 1) * sizeof(WCHAR));
  185. if (ERROR_SUCCESS != lStatus) {
  186. RegCloseKey(hKey2);
  187. return lStatus;
  188. }
  189. dwData = 3;
  190. lStatus = RegSetValueExW(hKey2,
  191. L"Section1DriveType1",
  192. 0,
  193. REG_DWORD,
  194. (BYTE*)&dwData,
  195. sizeof(DWORD));
  196. if (ERROR_SUCCESS != lStatus) {
  197. RegCloseKey(hKey2);
  198. return lStatus;
  199. }
  200. dwData = 1;
  201. lStatus = RegSetValueExW(hKey2,
  202. L"Section1Paths",
  203. 0,
  204. REG_DWORD,
  205. (BYTE*)&dwData,
  206. sizeof(DWORD));
  207. if (ERROR_SUCCESS != lStatus) {
  208. RegCloseKey(hKey2);
  209. return lStatus;
  210. }
  211. dwData = 1033;
  212. lStatus = RegSetValueExW(hKey2,
  213. L"CatalogLCID",
  214. 0,
  215. REG_DWORD,
  216. (BYTE*)&dwData,
  217. sizeof(DWORD));
  218. if (ERROR_SUCCESS != lStatus) {
  219. RegCloseKey(hKey2);
  220. return lStatus;
  221. }
  222. dwData = 1;
  223. lStatus = RegSetValueExW(hKey2,
  224. L"CatalogVersionID",
  225. 0,
  226. REG_DWORD,
  227. (BYTE*)&dwData, sizeof(DWORD));
  228. if (ERROR_SUCCESS != lStatus) {
  229. RegCloseKey(hKey2);
  230. return lStatus;
  231. }
  232. }
  233. RegCloseKey(hKey2);
  234. return lStatus;
  235. }
  236. /*++
  237. Register hooked functions
  238. --*/
  239. BOOL
  240. NOTIFY_FUNCTION(
  241. DWORD fdwReason)
  242. {
  243. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  244. Works99();
  245. }
  246. return TRUE;
  247. }
  248. HOOK_BEGIN
  249. CALL_NOTIFY_FUNCTION
  250. HOOK_END
  251. IMPLEMENT_SHIM_END