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.

374 lines
14 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. #include "foldinc.h" // Standard shell\folder includes
  18. extern const WCHAR c_szNetShellDll[];
  19. //---[ Constants ]------------------------------------------------------------
  20. static const WCHAR* c_szShellFoldDefaultIconVal = c_szNetShellDll;
  21. static const WCHAR c_szShellFolderAttributeVal[] = L"Attributes";
  22. static const WCHAR c_szShellFolderLocalizedString[] = L"LocalizedString";
  23. static const WCHAR c_szShellFolderInfoTip[] = L"InfoTip";
  24. static const WCHAR c_szShellFolderClsID[] =
  25. L"CLSID\\{7007ACC7-3202-11D1-AAD2-00805FC1270E}";
  26. static const WCHAR c_szShellFolder98ClsID[] =
  27. L"CLSID\\{992CFFA0-F557-101A-88EC-00DD010CCC48}";
  28. static const WCHAR c_szShellFoldDefaultIcon[] =
  29. L"CLSID\\{7007ACC7-3202-11D1-AAD2-00805FC1270E}\\DefaultIcon";
  30. static const WCHAR c_szShellFoldDefaultIcon98[] =
  31. L"CLSID\\{992CFFA0-F557-101A-88EC-00DD010CCC48}\\DefaultIcon";
  32. static const WCHAR c_szShellFolderKey[] =
  33. L"CLSID\\{7007ACC7-3202-11D1-AAD2-00805FC1270E}\\ShellFolder";
  34. static const WCHAR c_szShellFolderKey98[] =
  35. L"CLSID\\{992CFFA0-F557-101A-88EC-00DD010CCC48}\\ShellFolder";
  36. static const WCHAR c_szDotDun[] = L".dun";
  37. static const WCHAR c_szDunFile[] = L"dunfile";
  38. static const WCHAR c_szDunFileFriendlyName[] = L"Dialup Networking File";
  39. static const WCHAR c_szDefaultIcon[] = L"DefaultIcon";
  40. static const WCHAR c_szDunIconPath[] = L"%SystemRoot%\\system32\\netshell.dll,1";
  41. static const WCHAR c_szShellOpenCommand[] = L"shell\\open\\command";
  42. static const WCHAR c_szNetShellEntry[] =
  43. L"%SystemRoot%\\system32\\RUNDLL32.EXE NETSHELL.DLL,InvokeDunFile %1";
  44. static const WCHAR c_szApplicationsNetShell[] =
  45. L"Applications\\netshell.dll";
  46. static const WCHAR c_szNoOpenWith[] = L"NoOpenWith";
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: HrRegisterFolderClass
  50. //
  51. // Purpose: Fix the registry values for the Shell entries under HKCR,
  52. // CLSID\{CLSID}. The code generated from the RGS script doesn't
  53. // support our replaceable params by default, so we'll fix
  54. // it up after the fact.
  55. //
  56. // Arguments:
  57. // (none)
  58. //
  59. // Returns:
  60. //
  61. // Author: jeffspr 23 Sep 1997
  62. //
  63. // Notes:
  64. //
  65. HRESULT HrRegisterFolderClass()
  66. {
  67. HRESULT hr = S_OK;
  68. LONG lResult = 0;
  69. WCHAR szRegValue[MAX_PATH+1];
  70. WCHAR szWinDir[MAX_PATH+1];
  71. // Adjust the AppID for Local Server or Service
  72. CRegKey keyShellDefaultIcon;
  73. CRegKey keyShellFolder;
  74. if (GetSystemWindowsDirectory(szWinDir, MAX_PATH+1))
  75. {
  76. lResult = keyShellDefaultIcon.Open(HKEY_CLASSES_ROOT, c_szShellFoldDefaultIcon);
  77. if (lResult == ERROR_SUCCESS)
  78. {
  79. wsprintfW(szRegValue, L"%s\\system32\\%s", szWinDir, c_szShellFoldDefaultIconVal);
  80. keyShellDefaultIcon.SetValue(szRegValue);
  81. keyShellDefaultIcon.Close();
  82. lResult = keyShellFolder.Open(HKEY_CLASSES_ROOT, c_szShellFolderKey);
  83. if (lResult == ERROR_SUCCESS)
  84. {
  85. DWORD dwFlags = SFGAO_FOLDER;
  86. hr = HrRegSetValueEx(keyShellFolder,
  87. c_szShellFolderAttributeVal,
  88. REG_BINARY,
  89. (LPBYTE) &dwFlags,
  90. sizeof (dwFlags));
  91. keyShellFolder.Close();
  92. }
  93. // Write the MUI versions of LocalizedString & InfoTip out to the registry
  94. lResult = keyShellFolder.Open(HKEY_CLASSES_ROOT, c_szShellFolderClsID);
  95. if (lResult == ERROR_SUCCESS)
  96. {
  97. TCHAR szLocalizedString[MAX_PATH];
  98. TCHAR szInfoTip[MAX_PATH];
  99. wsprintf(szLocalizedString, _T("@%s\\system32\\%s,-%d"), szWinDir, c_szNetShellDll, IDS_CONFOLD_NAME);
  100. wsprintf(szInfoTip, _T("@%s\\system32\\%s,-%d"), szWinDir, c_szNetShellDll, IDS_CONFOLD_INFOTIP);
  101. hr = HrRegSetValueEx(keyShellFolder,
  102. c_szShellFolderLocalizedString,
  103. REG_SZ,
  104. (LPBYTE) &szLocalizedString,
  105. (lstrlen(szLocalizedString) + 1) * sizeof(TCHAR));
  106. hr = HrRegSetValueEx(keyShellFolder,
  107. c_szShellFolderInfoTip,
  108. REG_SZ,
  109. (LPBYTE) &szInfoTip,
  110. (lstrlen(szInfoTip) + 1) * sizeof(TCHAR));
  111. keyShellFolder.Close();
  112. }
  113. lResult = keyShellFolder.Open(HKEY_CLASSES_ROOT, c_szShellFolder98ClsID);
  114. if (lResult == ERROR_SUCCESS)
  115. {
  116. TCHAR szLocalizedString[MAX_PATH];
  117. TCHAR szInfoTip[MAX_PATH];
  118. wsprintf(szLocalizedString, _T("@%s\\system32\\%s,-%d"), szWinDir, c_szNetShellDll, IDS_CONFOLD_NAME);
  119. wsprintf(szInfoTip, _T("@%s\\system32\\%s,-%d"), szWinDir, c_szNetShellDll, IDS_CONFOLD_INFOTIP);
  120. hr = HrRegSetValueEx(keyShellFolder,
  121. c_szShellFolderLocalizedString,
  122. REG_SZ,
  123. (LPBYTE) &szLocalizedString,
  124. (lstrlen(szLocalizedString) + 1) * sizeof(TCHAR));
  125. hr = HrRegSetValueEx(keyShellFolder,
  126. c_szShellFolderInfoTip,
  127. REG_SZ,
  128. (LPBYTE) &szInfoTip,
  129. (lstrlen(szInfoTip) + 1) * sizeof(TCHAR));
  130. keyShellFolder.Close();
  131. }
  132. // added for #413840
  133. CRegKey keyShellDefaultIcon98;
  134. CRegKey keyShellFolder98;
  135. lResult = keyShellDefaultIcon98.Open(HKEY_CLASSES_ROOT, c_szShellFoldDefaultIcon98);
  136. if (lResult == ERROR_SUCCESS)
  137. {
  138. wsprintfW(szRegValue, L"%s\\system32\\%s", szWinDir, c_szShellFoldDefaultIconVal);
  139. keyShellDefaultIcon98.SetValue(szRegValue);
  140. keyShellDefaultIcon98.Close();
  141. }
  142. lResult = keyShellFolder98.Open(HKEY_CLASSES_ROOT, c_szShellFolderKey98);
  143. if (lResult == ERROR_SUCCESS)
  144. {
  145. DWORD dwFlags = SFGAO_FOLDER;
  146. hr = HrRegSetValueEx(keyShellFolder98,
  147. c_szShellFolderAttributeVal,
  148. REG_BINARY,
  149. (LPBYTE) &dwFlags,
  150. sizeof (dwFlags));
  151. keyShellFolder98.Close();
  152. }
  153. }
  154. else
  155. {
  156. // Translate LRESULT to HR
  157. //
  158. hr = HRESULT_FROM_WIN32(lResult);
  159. }
  160. }
  161. else // GetWindowsDirectory failed
  162. {
  163. hr = HrFromLastWin32Error();
  164. }
  165. return hr;
  166. }
  167. //+---------------------------------------------------------------------------
  168. //
  169. // Function: HrRegisterDUNFileAssociation
  170. //
  171. // Purpose: Add or upgrade the registry associate for .DUN fles
  172. //
  173. // Arguments:
  174. // (none)
  175. //
  176. // Returns:
  177. //
  178. // Author: tongl 2 Feb, 1999
  179. //
  180. // Notes:
  181. //
  182. HRESULT HrRegisterDUNFileAssociation()
  183. {
  184. HRESULT hr = S_OK;
  185. HKEY hkeyRootDun = NULL;
  186. HKEY hkeyRootDunFile = NULL;
  187. HKEY hkeyCommand = NULL;
  188. HKEY hkeyIcon = NULL;
  189. DWORD dwDisposition;
  190. WCHAR szFriendlyTypeName[MAX_PATH+1];
  191. // Create or open HKEY_CLASSES_ROOT\.dun
  192. hr = HrRegCreateKeyEx(HKEY_CLASSES_ROOT,
  193. c_szDotDun,
  194. REG_OPTION_NON_VOLATILE,
  195. KEY_WRITE,
  196. NULL,
  197. &hkeyRootDun,
  198. &dwDisposition);
  199. if (SUCCEEDED(hr))
  200. {
  201. if (REG_CREATED_NEW_KEY == dwDisposition)
  202. {
  203. hr = HrRegSetSz(hkeyRootDun,
  204. c_szEmpty,
  205. c_szDunFile);
  206. TraceError("Error creating file association for .dun files", hr);
  207. }
  208. RegSafeCloseKey(hkeyRootDun);
  209. if (SUCCEEDED(hr))
  210. {
  211. // create or open HKEY_CLASSES_ROOT\dunfile
  212. hr = HrRegCreateKeyEx(HKEY_CLASSES_ROOT,
  213. c_szDunFile,
  214. REG_OPTION_NON_VOLATILE,
  215. KEY_WRITE,
  216. NULL,
  217. &hkeyRootDunFile,
  218. &dwDisposition);
  219. if (SUCCEEDED(hr))
  220. {
  221. // Set friendly type name
  222. hr = HrRegSetValueEx(hkeyRootDunFile,
  223. c_szEmpty,
  224. REG_SZ,
  225. (LPBYTE) c_szDunFileFriendlyName,
  226. CbOfSzAndTermSafe(c_szDunFileFriendlyName));
  227. // trace the error
  228. TraceError("Error creating friendly name for .DUN files", hr);
  229. // Now, write MUI compliant friendly type name.
  230. wsprintf(szFriendlyTypeName,
  231. L"@%%SystemRoot%%\\system32\\%s,-%d",
  232. c_szNetShellDll,
  233. IDS_DUN_FRIENDLY_NAME);
  234. hr = HrRegSetValueEx(hkeyRootDunFile,
  235. L"FriendlyTypeName",
  236. REG_EXPAND_SZ,
  237. (LPBYTE)szFriendlyTypeName,
  238. CbOfSzAndTermSafe(szFriendlyTypeName));
  239. // trace the error
  240. TraceError("Error creating MUI friendly name for .DUN files", hr);
  241. hr = S_OK;
  242. // Set DefaultIcon
  243. // HKEY_CLASSES_ROOT\dunfile\DefaultIcon = "%SystemRoot%\System32\netshell.dll,1"
  244. hr = HrRegCreateKeyEx(hkeyRootDunFile,
  245. c_szDefaultIcon,
  246. REG_OPTION_NON_VOLATILE,
  247. KEY_WRITE,
  248. NULL,
  249. &hkeyIcon,
  250. &dwDisposition);
  251. if (SUCCEEDED(hr))
  252. {
  253. hr = HrRegSetValueEx (hkeyIcon,
  254. c_szEmpty,
  255. REG_EXPAND_SZ,
  256. (LPBYTE) c_szDunIconPath,
  257. CbOfSzAndTermSafe(c_szDunIconPath));
  258. RegSafeCloseKey(hkeyIcon);
  259. }
  260. // trace the error
  261. TraceError("Error creating DefaultIcon for .DUN files", hr);
  262. hr = S_OK;
  263. // Set or update Command to invoke
  264. // HKEY_CLASSES_ROOT\dunfile\shell\open\command =
  265. // "%%SystemRoot%%\system32\RUNDLL32.EXE NETSHELL.DLL,RunDunImport %1"
  266. hr = HrRegCreateKeyEx(hkeyRootDunFile,
  267. c_szShellOpenCommand,
  268. REG_OPTION_NON_VOLATILE,
  269. KEY_WRITE,
  270. NULL,
  271. &hkeyCommand,
  272. &dwDisposition);
  273. if (SUCCEEDED(hr))
  274. {
  275. hr = HrRegSetValueEx(hkeyCommand,
  276. c_szEmpty,
  277. REG_EXPAND_SZ,
  278. (LPBYTE) c_szNetShellEntry,
  279. CbOfSzAndTermSafe(c_szNetShellEntry));
  280. if(SUCCEEDED(hr))
  281. {
  282. HKEY hkeyNetShell = NULL;
  283. HRESULT hr2 = HrRegCreateKeyEx(HKEY_CLASSES_ROOT,
  284. c_szApplicationsNetShell,
  285. REG_OPTION_NON_VOLATILE,
  286. KEY_WRITE,
  287. NULL,
  288. &hkeyNetShell,
  289. &dwDisposition);
  290. if(SUCCEEDED(hr2) && (REG_CREATED_NEW_KEY == dwDisposition))
  291. {
  292. hr2 = HrRegSetValueEx(hkeyNetShell,
  293. c_szNoOpenWith,
  294. REG_SZ,
  295. (LPBYTE) c_szEmpty,
  296. CbOfSzAndTermSafe(c_szEmpty));
  297. }
  298. // trace the error
  299. TraceError("Error creating NoOpenWith value for .DUN files", hr2);
  300. RegSafeCloseKey(hkeyNetShell);
  301. }
  302. // trace the error
  303. TraceError("Error creating ShellCommand for .DUN files", hr);
  304. hr = S_OK;
  305. RegSafeCloseKey(hkeyCommand);
  306. }
  307. RegSafeCloseKey(hkeyRootDunFile);
  308. }
  309. }
  310. }
  311. return hr;
  312. }