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.

1750 lines
41 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. registry.c
  5. Abstract:
  6. This file provides access to the registry.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include "wizard.h"
  13. #pragma hdrstop
  14. BOOL
  15. CreateDeviceProvider(
  16. HKEY hKey,
  17. LPTSTR ProviderKey,
  18. LPTSTR FriendlyName,
  19. LPTSTR ImageName,
  20. LPTSTR ProviderName
  21. )
  22. {
  23. hKey = OpenRegistryKey( hKey, ProviderKey, TRUE, KEY_ALL_ACCESS );
  24. if (!hKey) {
  25. DebugPrint(( TEXT("could not create/open registry key (test)") ));
  26. return FALSE;
  27. }
  28. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  29. DebugPrint(( TEXT("could not add friendly name value") ));
  30. return FALSE;
  31. }
  32. if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) {
  33. DebugPrint(( TEXT("could not add image name value") ));
  34. return FALSE;
  35. }
  36. if (!SetRegistryString( hKey, REGVAL_PROVIDER_NAME, ProviderName )) {
  37. DebugPrint(( TEXT("could not add provider name value") ));
  38. return FALSE;
  39. }
  40. RegCloseKey( hKey );
  41. return TRUE;
  42. }
  43. BOOL
  44. CreateRoutingMethod(
  45. HKEY hKey,
  46. LPTSTR MethodName,
  47. LPTSTR FunctionName,
  48. LPTSTR FriendlyName,
  49. LPTSTR Guid
  50. )
  51. {
  52. hKey = OpenRegistryKey( hKey, MethodName, TRUE, KEY_ALL_ACCESS );
  53. if (!hKey) {
  54. DebugPrint(( TEXT("could not create/open registry key for routing method") ));
  55. return FALSE;
  56. }
  57. if (!SetRegistryString( hKey, REGVAL_FUNCTION_NAME, FunctionName )) {
  58. DebugPrint(( TEXT("could not add function name value") ));
  59. return FALSE;
  60. }
  61. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  62. DebugPrint(( TEXT("could not add friendly name value") ));
  63. return FALSE;
  64. }
  65. if (!SetRegistryString( hKey, REGVAL_GUID, Guid )) {
  66. DebugPrint(( TEXT("could not add function name value") ));
  67. return FALSE;
  68. }
  69. RegCloseKey( hKey );
  70. return TRUE;
  71. }
  72. BOOL
  73. CreateMicrosoftRoutingExtension(
  74. HKEY hKey,
  75. LPTSTR RoutingKey,
  76. LPTSTR FriendlyName,
  77. LPTSTR ImageName
  78. )
  79. {
  80. HKEY hKeyMethods;
  81. hKey = OpenRegistryKey( hKey, RoutingKey, TRUE, KEY_ALL_ACCESS );
  82. if (!hKey) {
  83. Assert(( ! TEXT("could not create/open registry key for routing extension") ));
  84. return FALSE;
  85. }
  86. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  87. Assert(( ! TEXT("could not add friendly name value") ));
  88. return FALSE;
  89. }
  90. if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) {
  91. Assert(( ! TEXT("could not add image name value") ));
  92. return FALSE;
  93. }
  94. hKeyMethods = OpenRegistryKey( hKey, REGKEY_ROUTING_METHODS, TRUE, KEY_ALL_ACCESS );
  95. if (!hKeyMethods) {
  96. Assert(( ! TEXT("could not create/open registry key for routing methods") ));
  97. return FALSE;
  98. }
  99. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_EMAIL, REGVAL_RM_EMAIL_FUNCTION, REGVAL_RM_EMAIL_FRIENDLY, REGVAL_RM_EMAIL_GUID );
  100. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_FOLDER, REGVAL_RM_FOLDER_FUNCTION, REGVAL_RM_FOLDER_FRIENDLY, REGVAL_RM_FOLDER_GUID );
  101. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_INBOX, REGVAL_RM_INBOX_FUNCTION, REGVAL_RM_INBOX_FRIENDLY, REGVAL_RM_INBOX_GUID );
  102. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_PRINTING, REGVAL_RM_PRINTING_FUNCTION, REGVAL_RM_PRINTING_FRIENDLY, REGVAL_RM_PRINTING_GUID );
  103. RegCloseKey( hKeyMethods );
  104. RegCloseKey( hKey );
  105. return TRUE;
  106. }
  107. VOID
  108. RegCreateFaxDevice(
  109. HKEY hKeyDev,
  110. DWORD PermanentLineID,
  111. DWORD Rings,
  112. DWORD Priority,
  113. DWORD Flags,
  114. LPTSTR DeviceName,
  115. LPTSTR ProviderName,
  116. LPTSTR Csid,
  117. LPTSTR Tsid,
  118. DWORD RoutingMask,
  119. LPTSTR RoutePrinterName,
  120. LPTSTR RouteDir,
  121. LPTSTR RouteProfile
  122. )
  123. {
  124. HKEY hKey;
  125. HKEY hKeyRouting;
  126. TCHAR PortName[32];
  127. _stprintf( PortName, TEXT("%08d"), PermanentLineID );
  128. hKey = OpenRegistryKey( hKeyDev, PortName, TRUE, KEY_ALL_ACCESS );
  129. if (!hKey) {
  130. Assert(( ! TEXT("Could not open device registry key") ));
  131. return;
  132. }
  133. if (!SetRegistryDword( hKey, REGVAL_PERMANENT_LINEID, PermanentLineID )) {
  134. Assert(( ! TEXT("Could not set device id registry value") ));
  135. }
  136. if (!SetRegistryDword( hKey, REGVAL_FLAGS, Flags )) {
  137. Assert(( ! TEXT("Could not set device flags registry value") ));
  138. }
  139. if (!SetRegistryDword( hKey, REGVAL_RINGS, Rings )) {
  140. Assert(( ! TEXT("Could not set device rings registry value") ));
  141. }
  142. if (!SetRegistryDword( hKey, REGVAL_PRIORITY, Priority )) {
  143. Assert(( ! TEXT("Could not set device rings registry value") ));
  144. }
  145. if (!SetRegistryString( hKey, REGVAL_DEVICE_NAME, DeviceName )) {
  146. Assert(( ! TEXT("Could not set device name registry value") ));
  147. }
  148. if (!SetRegistryString( hKey, REGVAL_PROVIDER, ProviderName )) {
  149. Assert(( ! TEXT("Could not set provider name registry value") ));
  150. }
  151. if (!SetRegistryString( hKey, REGVAL_ROUTING_CSID, Csid )) {
  152. Assert(( ! TEXT("Could not set csid registry value") ));
  153. }
  154. if (!SetRegistryString( hKey, REGVAL_ROUTING_TSID, Tsid )) {
  155. Assert(( ! TEXT("Could not set csid registry value") ));
  156. }
  157. hKeyRouting = OpenRegistryKey( hKey, REGKEY_ROUTING, TRUE, KEY_ALL_ACCESS );
  158. if (!hKeyRouting) {
  159. Assert(( ! TEXT("Could not open routing registry key") ));
  160. return;
  161. }
  162. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PRINTER, RoutePrinterName )) {
  163. Assert(( ! TEXT("Could not set printer name registry value") ));
  164. }
  165. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_DIR, RouteDir )) {
  166. Assert(( ! TEXT("Could not set routing dir registry value") ));
  167. }
  168. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PROFILE, RouteProfile )) {
  169. Assert(( ! TEXT("Could not set routing profile name registry value") ));
  170. }
  171. if (!SetRegistryDword( hKeyRouting, REGVAL_ROUTING_MASK, RoutingMask )) {
  172. Assert(( ! TEXT("Could not set routing mask registry value") ));
  173. }
  174. RegCloseKey( hKeyRouting );
  175. RegCloseKey( hKey );
  176. }
  177. BOOL
  178. SetServerRegistryData(
  179. VOID
  180. )
  181. {
  182. HKEY hKey;
  183. LONG rVal;
  184. DWORD i;
  185. HKEY hKeyDev;
  186. HANDLE hNull;
  187. STARTUPINFO si;
  188. PROCESS_INFORMATION pi;
  189. TCHAR CmdLine[128];
  190. DWORD RoutingMask;
  191. LPTSTR LodCmdLine;
  192. //
  193. // set top level defaults
  194. //
  195. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS );
  196. if (!hKey) {
  197. Assert(( ! TEXT("Could not open software registry key") ));
  198. return FALSE;
  199. }
  200. if (InstallMode & INSTALL_NEW) {
  201. if (!SetRegistryDword( hKey, REGVAL_RETRIES, DEFAULT_REGVAL_RETRIES )) {
  202. Assert(( ! TEXT("Could not set retries registry value") ));
  203. }
  204. if (!SetRegistryDword( hKey, REGVAL_RETRYDELAY, DEFAULT_REGVAL_RETRYDELAY )) {
  205. Assert(( ! TEXT("Could not set retry delay registry value") ));
  206. }
  207. if (!SetRegistryDword( hKey, REGVAL_DIRTYDAYS, DEFAULT_REGVAL_DIRTYDAYS )) {
  208. Assert(( ! TEXT("Could not set dirty days registry value") ));
  209. }
  210. if (!SetRegistryDword( hKey, REGVAL_QUEUE_PAUSED, DEFAULT_REGVAL_QUEUE_PAUSED )) {
  211. Assert(( ! TEXT("Could not set queue paused registry value") ));
  212. }
  213. if (!SetRegistryDword( hKey, REGVAL_JOB_NUMBER, DEFAULT_REGVAL_JOB_NUMBER )) {
  214. Assert(( ! TEXT("Could not net job number registry value") ));
  215. }
  216. if (!SetRegistryDword( hKey, REGVAL_BRANDING, DEFAULT_REGVAL_BRANDING )) {
  217. Assert(( ! TEXT("Could not set branding registry value") ));
  218. }
  219. if (!SetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID, DEFAULT_REGVAL_USEDEVICETSID )) {
  220. Assert(( ! TEXT("Could not set usedevicetsid registry value") ));
  221. }
  222. if (!SetRegistryString( hKey, REGVAL_INBOUND_PROFILE, EMPTY_STRING )) {
  223. Assert(( ! TEXT("Could not set inbound profile registry value") ));
  224. }
  225. if (!SetRegistryDword( hKey, REGVAL_SERVERCP, DEFAULT_REGVAL_SERVERCP )) {
  226. Assert(( ! TEXT("Could not set servercp registry value") ));
  227. }
  228. if (!SetRegistryDword( hKey, REGVAL_STARTCHEAP, DEFAULT_REGVAL_STARTCHEAP )) {
  229. Assert(( ! TEXT("Could not set startcheap registry value") ));
  230. }
  231. if (!SetRegistryDword( hKey, REGVAL_STOPCHEAP, DEFAULT_REGVAL_STOPCHEAP )) {
  232. Assert(( ! TEXT("Could not set stopcheap registry value") ));
  233. }
  234. if (!SetRegistryDword( hKey, REGVAL_ARCHIVEFLAG, DEFAULT_REGVAL_ARCHIVEFLAG )) {
  235. Assert(( ! TEXT("Could not set archiveflag registry value") ));
  236. }
  237. if (!SetRegistryString( hKey, REGVAL_ARCHIVEDIR, DEFAULT_REGVAL_ARCHIVEDIR )) {
  238. Assert(( ! TEXT("Could not set archive dir registry value") ));
  239. }
  240. RegCloseKey( hKey );
  241. }
  242. if (InstallMode & INSTALL_NEW) {
  243. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_DEVICES, TRUE, KEY_ALL_ACCESS );
  244. if (!hKey) {
  245. Assert(( ! TEXT("Could not open devices registry key") ));
  246. return FALSE;
  247. }
  248. //
  249. // set the routing mask
  250. //
  251. RoutingMask = 0;
  252. if (WizData.RoutePrint) {
  253. RoutingMask |= LR_PRINT;
  254. }
  255. if (WizData.RouteStore) {
  256. RoutingMask |= LR_STORE;
  257. }
  258. if (WizData.RouteMail) {
  259. RoutingMask |= LR_INBOX;
  260. }
  261. if (WizData.UseDefaultPrinter || WizData.RoutePrinterName[0]) {
  262. RoutingMask |= LR_PRINT;
  263. }
  264. //
  265. // enumerate the devices and create the registry data
  266. //
  267. for (i=0; i<FaxDevices; i++) {
  268. if ((InstallType & FAX_INSTALL_WORKSTATION) && (!LineInfo[i].Selected)) {
  269. continue;
  270. }
  271. RegCreateFaxDevice(
  272. hKeyDev,
  273. LineInfo[i].PermanentLineID,
  274. LineInfo[i].Rings,
  275. i+1,
  276. LineInfo[i].Flags,
  277. LineInfo[i].DeviceName,
  278. LineInfo[i].ProviderName,
  279. WizData.Csid,
  280. WizData.Tsid,
  281. RoutingMask,
  282. WizData.RoutePrinterName,
  283. WizData.RouteDir,
  284. WizData.RouteProfile
  285. );
  286. }
  287. RegCloseKey( hKeyDev );
  288. }
  289. //
  290. // create the device providers
  291. //
  292. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_DEVICE_PROVIDER_KEY, TRUE, KEY_ALL_ACCESS );
  293. if (!hKeyDev) {
  294. Assert(( ! TEXT("Could not open device provider registry key") ));
  295. return FALSE;
  296. }
  297. CreateDeviceProvider(
  298. hKeyDev,
  299. REGKEY_MODEM_PROVIDER,
  300. REGVAL_MODEM_FRIENDLY_NAME_TEXT,
  301. REGVAL_MODEM_IMAGE_NAME_TEXT,
  302. REGVAL_MODEM_PROVIDER_NAME_TEXT
  303. );
  304. RegCloseKey( hKeyDev );
  305. //
  306. // create the routing extensions
  307. //
  308. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_ROUTING_EXTENSION_KEY, TRUE, KEY_ALL_ACCESS );
  309. if (!hKeyDev) {
  310. Assert(( ! TEXT("Could not open routing extension registry key") ));
  311. return FALSE;
  312. }
  313. CreateMicrosoftRoutingExtension(
  314. hKeyDev,
  315. REGKEY_ROUTING_EXTENSION,
  316. REGVAL_ROUTE_FRIENDLY_NAME,
  317. REGVAL_ROUTE_IMAGE_NAME
  318. );
  319. RegCloseKey( hKeyDev );
  320. //
  321. // set the user's preferences
  322. //
  323. if (InstallMode & INSTALL_NEW) {
  324. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  325. if (!hKey) {
  326. Assert(( ! TEXT("Could not open fax setup registry key") ));
  327. return FALSE;
  328. }
  329. if (!SetRegistryStringExpand( hKey, REGVAL_CP_LOCATION, DEFAULT_COVERPAGE_DIR )) {
  330. Assert(( ! TEXT("Could not set coverpage dir registry value") ));
  331. }
  332. if (!SetRegistryString( hKey, REGVAL_CP_EDITOR, COVERPAGE_EDITOR )) {
  333. Assert(( ! TEXT("Could not set coverpage editor registry value") ));
  334. }
  335. if (!SetRegistryString(
  336. hKey,
  337. REGVAL_FAX_PROFILE,
  338. WizData.MapiProfile[0] ? WizData.MapiProfile : DEFAULT_FAX_PROFILE ))
  339. {
  340. Assert(( ! TEXT("Could not set fax profile name registry value") ));
  341. }
  342. RegCloseKey( hKey );
  343. }
  344. //
  345. // create the perfmon registry data
  346. //
  347. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAXPERF, TRUE, KEY_ALL_ACCESS );
  348. if (!hKey) {
  349. Assert(( ! TEXT("Could not open fax perfmon registry key") ));
  350. return FALSE;
  351. }
  352. if (!SetRegistryStringExpand( hKey, REGVAL_OPEN, REGVAL_OPEN_DATA )) {
  353. Assert(( ! TEXT("Could not set perfmon registry value") ));
  354. }
  355. if (!SetRegistryStringExpand( hKey, REGVAL_CLOSE, REGVAL_CLOSE_DATA )) {
  356. Assert(( ! TEXT("Could not set perfmon registry value") ));
  357. }
  358. if (!SetRegistryStringExpand( hKey, REGVAL_COLLECT, REGVAL_COLLECT_DATA )) {
  359. Assert(( ! TEXT("Could not set perfmon registry value") ));
  360. }
  361. if (!SetRegistryStringExpand( hKey, REGVAL_LIBRARY, REGVAL_LIBRARY_DATA )) {
  362. Assert(( ! TEXT("Could not set perfmon registry value") ));
  363. }
  364. RegCloseKey( hKey );
  365. //
  366. // load the performance counters
  367. //
  368. hNull = CreateFile(
  369. TEXT("nul"),
  370. GENERIC_READ | GENERIC_WRITE,
  371. 0,
  372. NULL,
  373. OPEN_EXISTING,
  374. 0,
  375. NULL
  376. );
  377. if (hNull == INVALID_HANDLE_VALUE) {
  378. rVal = GetLastError();
  379. return FALSE;
  380. }
  381. GetStartupInfo( &si );
  382. si.hStdInput = hNull;
  383. si.hStdOutput = hNull;
  384. si.hStdError = hNull;
  385. si.dwFlags = STARTF_USESTDHANDLES;
  386. _tcscpy( CmdLine, TEXT("unlodctr fax") );
  387. rVal = CreateProcess(
  388. NULL,
  389. CmdLine,
  390. NULL,
  391. NULL,
  392. TRUE,
  393. DETACHED_PROCESS,
  394. NULL,
  395. NULL,
  396. &si,
  397. &pi
  398. );
  399. if (!rVal) {
  400. rVal = GetLastError();
  401. return FALSE;
  402. }
  403. WaitForSingleObject( pi.hProcess, INFINITE );
  404. if (NtGuiMode) {
  405. LodCmdLine = ExpandEnvironmentString( TEXT("lodctr %windir%\\system32\\faxperf.ini") );
  406. if (!LodCmdLine) {
  407. return FALSE;
  408. }
  409. } else {
  410. LodCmdLine = TEXT("lodctr faxperf.ini");
  411. }
  412. _tcscpy( CmdLine, LodCmdLine );
  413. rVal = CreateProcess(
  414. NULL,
  415. CmdLine,
  416. NULL,
  417. NULL,
  418. TRUE,
  419. DETACHED_PROCESS,
  420. NULL,
  421. NtGuiMode ? NULL : SourceDirectory,
  422. &si,
  423. &pi
  424. );
  425. if (!rVal) {
  426. rVal = GetLastError();
  427. return FALSE;
  428. }
  429. WaitForSingleObject( pi.hProcess, INFINITE );
  430. CloseHandle( hNull );
  431. CreateFileAssociation(
  432. COVERPAGE_EXTENSION,
  433. COVERPAGE_ASSOC_NAME,
  434. COVERPAGE_ASSOC_DESC,
  435. COVERPAGE_OPEN_COMMAND,
  436. NULL,
  437. NULL,
  438. NULL,
  439. 0
  440. );
  441. return TRUE;
  442. }
  443. BOOL
  444. SetClientRegistryData(
  445. VOID
  446. )
  447. {
  448. TCHAR FaxNumber[LT_USER_NAME+LT_AREA_CODE+1];
  449. HKEY hKey;
  450. if (InstallMode & INSTALL_NEW) {
  451. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_USERINFO, TRUE, KEY_ALL_ACCESS );
  452. if (!hKey) {
  453. Assert(( ! TEXT("Could not open fax user info registry key") ));
  454. return FALSE;
  455. }
  456. if (!SetRegistryString( hKey, REGVAL_FULLNAME, WizData.UserName )) {
  457. Assert(( ! TEXT("Could not set user name registry value") ));
  458. }
  459. if (WizData.AreaCode[0]) {
  460. _stprintf( FaxNumber, TEXT("(%s) %s"), WizData.AreaCode, WizData.PhoneNumber );
  461. } else {
  462. _tcscpy( FaxNumber, WizData.PhoneNumber );
  463. }
  464. if (!SetRegistryString( hKey, REGVAL_FAX_NUMBER, FaxNumber )) {
  465. Assert(( ! TEXT("Could not set fax phone number registry value") ));
  466. }
  467. if (!SetRegistryDword( hKey, REGVAL_LAST_COUNTRYID, CurrentCountryId )) {
  468. Assert(( ! TEXT("Could not set last country id registry value") ));
  469. }
  470. if (!SetRegistryDword( hKey, REGVAL_DIAL_AS_ENTERED, 0 )) {
  471. Assert(( ! TEXT("Could not set dial as entered registry value") ));
  472. }
  473. if (!SetRegistryDword( hKey, REGVAL_ALWAYS_ON_TOP, BST_UNCHECKED )) {
  474. Assert(( ! TEXT("Could not set always on top registry value") ));
  475. }
  476. if (!SetRegistryDword( hKey, REGVAL_SOUND_NOTIFICATION, BST_UNCHECKED )) {
  477. Assert(( ! TEXT("Could not set sound notification registry value") ));
  478. }
  479. if (!SetRegistryDword( hKey, REGVAL_ENABLE_MANUAL_ANSWER, BST_UNCHECKED )) {
  480. Assert(( ! TEXT("Could not set enable manual answer registry value") ));
  481. }
  482. if (!SetRegistryDword( hKey, REGVAL_TASKBAR, BST_CHECKED )) {
  483. Assert(( ! TEXT("Could not set enable manual answer registry value") ));
  484. }
  485. if (!SetRegistryDword( hKey, REGVAL_VISUAL_NOTIFICATION, BST_CHECKED )) {
  486. Assert(( ! TEXT("Could not set visual notification registry value") ));
  487. }
  488. if (!SetRegistryString( hKey, REGVAL_LAST_RECAREACODE, CurrentAreaCode )) {
  489. Assert(( ! TEXT("Could not set area code registry value") ));
  490. }
  491. RegCloseKey( hKey );
  492. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  493. if (!hKey) {
  494. Assert(( ! TEXT("Could not open fax setup registry key") ));
  495. return FALSE;
  496. }
  497. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED, TRUE )) {
  498. Assert(( ! TEXT("Could not set installed registry value") ));
  499. }
  500. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE, FAX_INSTALL_NETWORK_CLIENT )) {
  501. Assert(( ! TEXT("Could not set install type registry value") ));
  502. }
  503. if (!SetRegistryStringExpand( hKey, REGVAL_CP_LOCATION, DEFAULT_COVERPAGE_DIR )) {
  504. Assert(( ! TEXT("Could not set coverpage dir registry value") ));
  505. }
  506. if (!SetRegistryStringExpand( hKey, REGVAL_CP_EDITOR, COVERPAGE_EDITOR )) {
  507. Assert(( ! TEXT("Could not set coverpage editor registry value") ));
  508. }
  509. if (!SetRegistryString(
  510. hKey,
  511. REGVAL_FAX_PROFILE,
  512. WizData.MapiProfile[0] ? WizData.MapiProfile : DEFAULT_FAX_PROFILE ))
  513. {
  514. Assert(( ! TEXT("Could not set profile name registry value") ));
  515. }
  516. RegCloseKey( hKey );
  517. }
  518. #ifdef MSFT_FAXVIEW
  519. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAXVIEW, TRUE, KEY_ALL_ACCESS );
  520. if (!hKey) {
  521. Assert(( ! TEXT("Could not open fax viewer registry key") ));
  522. return FALSE;
  523. }
  524. if (!SetRegistryString( hKey, REGVAL_LAST_DIR, WizData.RouteDir )) {
  525. Assert(( ! TEXT("Could not set coverpage editor registry value") ));
  526. }
  527. RegCloseKey( hKey );
  528. #endif
  529. CreateFileAssociation(
  530. COVERPAGE_EXTENSION,
  531. COVERPAGE_ASSOC_NAME,
  532. COVERPAGE_ASSOC_DESC,
  533. COVERPAGE_OPEN_COMMAND,
  534. NULL,
  535. NULL,
  536. NULL,
  537. 0
  538. );
  539. #ifdef MSFT_FAXVIEW
  540. CreateFileAssociation(
  541. FAXVIEW_EXTENSION,
  542. FAXVIEW_ASSOC_NAME,
  543. FAXVIEW_ASSOC_DESC,
  544. FAXVIEW_OPEN_COMMAND,
  545. FAXVIEW_PRINT_COMMAND,
  546. FAXVIEW_PRINTTO_COMMAND,
  547. FAXVIEW_FILE_NAME,
  548. FAXVIEW_ICON_INDEX
  549. );
  550. CreateFileAssociation(
  551. FAXVIEW_EXTENSION2,
  552. FAXVIEW_ASSOC_NAME,
  553. FAXVIEW_ASSOC_DESC,
  554. FAXVIEW_OPEN_COMMAND,
  555. FAXVIEW_PRINT_COMMAND,
  556. FAXVIEW_PRINTTO_COMMAND,
  557. FAXVIEW_FILE_NAME,
  558. FAXVIEW_ICON_INDEX
  559. );
  560. #endif
  561. #ifdef USE_WORDPAD
  562. if (IsWordpadInstalled()) {
  563. ChangeTxtFileAssociation();
  564. } else if (InstallWordpad()) {
  565. ChangeTxtFileAssociation();
  566. }
  567. #endif
  568. return TRUE;
  569. }
  570. BOOL
  571. SetSoundRegistryData()
  572. {
  573. HKEY hKey;
  574. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL, TRUE, KEY_ALL_ACCESS );
  575. if (!hKey) {
  576. Assert(( ! TEXT("Could not open event label registry key") ));
  577. return FALSE;
  578. }
  579. if (!SetRegistryString( hKey, NULL, TEXT("Incoming Fax") )) {
  580. Assert(( ! TEXT("Could not set event label registry value") ));
  581. }
  582. RegCloseKey( hKey );
  583. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAXSTAT, TRUE, KEY_ALL_ACCESS );
  584. if (!hKey) {
  585. Assert(( ! TEXT("Could not open faxstat registry key") ));
  586. return FALSE;
  587. }
  588. if (!SetRegistryString( hKey, NULL, TEXT("Fax Monitor") )) {
  589. Assert(( ! TEXT("Could not set faxstat registry value") ));
  590. }
  591. RegCloseKey( hKey );
  592. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_DEFAULT, TRUE, KEY_ALL_ACCESS );
  593. if (!hKey) {
  594. Assert(( ! TEXT("Could not open default sound registry key") ));
  595. return FALSE;
  596. }
  597. if (!SetRegistryString( hKey, NULL, TEXT("ringin.wav") )) {
  598. Assert(( ! TEXT("Could not set default sound registry value") ));
  599. }
  600. RegCloseKey( hKey );
  601. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_CURRENT, TRUE, KEY_ALL_ACCESS );
  602. if (!hKey) {
  603. Assert(( ! TEXT("Could not open current sound registry key") ));
  604. return FALSE;
  605. }
  606. if (!SetRegistryString( hKey, NULL, TEXT("ringin.wav") )) {
  607. Assert(( ! TEXT("Could not set current sound registry value") ));
  608. }
  609. RegCloseKey( hKey );
  610. }
  611. BOOL
  612. GetUserInformation(
  613. LPTSTR *UserName,
  614. LPTSTR *FaxNumber,
  615. LPTSTR *AreaCode
  616. )
  617. {
  618. HKEY hKey;
  619. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_USERINFO, TRUE, KEY_ALL_ACCESS );
  620. if (!hKey) {
  621. Assert(( ! TEXT("Could not open fax user info registry key") ));
  622. return FALSE;
  623. }
  624. *UserName = GetRegistryString( hKey, REGVAL_FULLNAME, EMPTY_STRING );
  625. if (!*UserName) {
  626. Assert(( ! TEXT("Could not query user name registry value") ));
  627. }
  628. *FaxNumber = GetRegistryString( hKey, REGVAL_FAX_NUMBER, EMPTY_STRING );
  629. if (!*FaxNumber) {
  630. Assert(( ! TEXT("Could not query fax number registry value") ));
  631. }
  632. *AreaCode = MemAlloc( (LT_AREA_CODE+1) * sizeof(TCHAR) );
  633. if (*AreaCode && (*FaxNumber)[0] == TEXT('(')) {
  634. LPTSTR p = _tcschr( *FaxNumber, TEXT('-') );
  635. if (p) {
  636. *p = 0;
  637. _tcscpy( *AreaCode, &(*FaxNumber)[1] );
  638. *p = TEXT('-');
  639. }
  640. }
  641. RegCloseKey( hKey );
  642. return TRUE;
  643. }
  644. BOOL
  645. GetInstallationInfo(
  646. LPDWORD Installed,
  647. LPDWORD InstallType,
  648. LPDWORD InstalledPlatforms,
  649. LPDWORD Enabled
  650. )
  651. {
  652. HKEY hKey;
  653. LONG rVal;
  654. if (Installed) {
  655. *Installed = 0;
  656. }
  657. if (InstallType) {
  658. *InstallType = 0;
  659. }
  660. if (InstalledPlatforms) {
  661. *InstalledPlatforms = 0;
  662. }
  663. rVal = RegOpenKey(
  664. HKEY_LOCAL_MACHINE,
  665. REGKEY_FAX_SETUP,
  666. &hKey
  667. );
  668. if (rVal != ERROR_SUCCESS) {
  669. DebugPrint(( TEXT("Could not open setup registry key, ec=0x%08x"), rVal ));
  670. return FALSE;
  671. }
  672. if (Installed) {
  673. *Installed = GetRegistryDword( hKey, REGVAL_FAXINSTALLED );
  674. }
  675. if (InstallType) {
  676. *InstallType = GetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE );
  677. }
  678. if (InstalledPlatforms) {
  679. *InstalledPlatforms = GetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS );
  680. }
  681. RegCloseKey( hKey );
  682. return TRUE;
  683. }
  684. BOOL
  685. SetInstalledFlag(
  686. BOOL Installed
  687. )
  688. {
  689. HKEY hKey;
  690. HKEY hKeySetup;
  691. DWORD RoutingMask;
  692. //
  693. // set the routing mask
  694. //
  695. RoutingMask = 0;
  696. if (WizData.RoutePrint) {
  697. RoutingMask |= LR_PRINT;
  698. }
  699. if (WizData.RouteStore) {
  700. RoutingMask |= LR_STORE;
  701. }
  702. if (WizData.RouteMail) {
  703. RoutingMask |= LR_INBOX;
  704. }
  705. if (WizData.UseDefaultPrinter || WizData.RoutePrinterName[0]) {
  706. RoutingMask |= LR_PRINT;
  707. }
  708. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  709. if (!hKey) {
  710. Assert(( ! TEXT("Could not open setup registry key") ));
  711. return FALSE;
  712. }
  713. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED, Installed )) {
  714. Assert(( ! TEXT("Could not set installed registry value") ));
  715. }
  716. hKeySetup = OpenRegistryKey( hKey, REGKEY_FAX_SETUP_ORIG, TRUE, KEY_ALL_ACCESS );
  717. if (!hKeySetup) {
  718. Assert(( ! TEXT("Could not open fax setup registry key") ));
  719. return FALSE;
  720. }
  721. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_PRINTER, WizData.RoutePrinterName )) {
  722. Assert(( ! TEXT("Could not set printer name registry value") ));
  723. }
  724. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_DIR, WizData.RouteDir )) {
  725. Assert(( ! TEXT("Could not set routing dir registry value") ));
  726. }
  727. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_PROFILE, WizData.RouteProfile )) {
  728. Assert(( ! TEXT("Could not set routing profile name registry value") ));
  729. }
  730. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_CSID, WizData.Csid )) {
  731. Assert(( ! TEXT("Could not set routing csid registry value") ));
  732. }
  733. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_TSID, WizData.Tsid )) {
  734. Assert(( ! TEXT("Could not set routing tsid registry value") ));
  735. }
  736. if (!SetRegistryDword( hKeySetup, REGVAL_ROUTING_MASK, RoutingMask )) {
  737. Assert(( ! TEXT("Could not set routing mask registry value") ));
  738. }
  739. if (!SetRegistryDword( hKeySetup, REGVAL_RINGS, 2 )) {
  740. Assert(( ! TEXT("Could not set rings registry value") ));
  741. }
  742. RegCloseKey( hKeySetup );
  743. RegCloseKey( hKey );
  744. return TRUE;
  745. }
  746. BOOL
  747. SetInstallType(
  748. DWORD InstallType
  749. )
  750. {
  751. HKEY hKey;
  752. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  753. if (!hKey) {
  754. Assert(( ! TEXT("Could not open setup registry key") ));
  755. return FALSE;
  756. }
  757. InstallType |= GetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE );
  758. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE, InstallType )) {
  759. Assert(( ! TEXT("Could not set install type registry value") ));
  760. }
  761. RegCloseKey( hKey );
  762. return TRUE;
  763. }
  764. BOOL
  765. SetInstalledPlatforms(
  766. DWORD PlatformsMask
  767. )
  768. {
  769. HKEY hKey;
  770. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  771. if (!hKey) {
  772. Assert(( ! TEXT("Could not open setup registry key") ));
  773. return FALSE;
  774. }
  775. PlatformsMask |= GetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS );
  776. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS, PlatformsMask )) {
  777. Assert(( ! TEXT("Could not set install type registry value") ));
  778. }
  779. RegCloseKey( hKey );
  780. return TRUE;
  781. }
  782. BOOL
  783. DeleteRegistryTree(
  784. HKEY hKey,
  785. LPTSTR SubKey
  786. )
  787. {
  788. LONG Rval;
  789. HKEY hKeyCur;
  790. TCHAR KeyName[256];
  791. DWORD KeyNameSize;
  792. FILETIME FileTime;
  793. DWORD KeyCount;
  794. Rval = RegOpenKeyEx( hKey, SubKey, 0, KEY_ALL_ACCESS, &hKeyCur );
  795. if (Rval != ERROR_SUCCESS) {
  796. return FALSE;
  797. }
  798. KeyCount = GetSubKeyCount( hKeyCur );
  799. if (KeyCount == 0) {
  800. RegCloseKey( hKeyCur );
  801. RegDeleteKey( hKey, SubKey );
  802. return TRUE;
  803. }
  804. while( TRUE ) {
  805. KeyNameSize = sizeof(KeyName);
  806. Rval = RegEnumKeyEx( hKeyCur, 0, KeyName, &KeyNameSize, 0, NULL, NULL, &FileTime );
  807. if (Rval == ERROR_NO_MORE_ITEMS) {
  808. break;
  809. } else if (Rval != ERROR_SUCCESS) {
  810. RegCloseKey( hKeyCur );
  811. return FALSE;
  812. }
  813. if (!DeleteRegistryTree( hKeyCur, KeyName )) {
  814. RegCloseKey( hKeyCur );
  815. return FALSE;
  816. }
  817. }
  818. RegCloseKey( hKeyCur );
  819. RegDeleteKey( hKey, SubKey );
  820. return TRUE;
  821. }
  822. BOOL
  823. DeleteFaxRegistryData(
  824. VOID
  825. )
  826. {
  827. LONG Rval;
  828. HKEY hKeyCur;
  829. STARTUPINFO si;
  830. PROCESS_INFORMATION pi;
  831. HANDLE hNull;
  832. TCHAR CmdLine[128];
  833. DeleteRegistryTree( HKEY_LOCAL_MACHINE, REGKEY_FAXSERVER );
  834. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_FAXSERVER );
  835. DeleteRegistryTree( HKEY_LOCAL_MACHINE, REGKEY_SETUP_UNINSTALL );
  836. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL );
  837. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_FAXSTAT );
  838. #ifdef MSFT_FAXVIEW
  839. DeleteRegistryTree( HKEY_CLASSES_ROOT, FAXVIEW_ASSOC_NAME );
  840. #endif
  841. Rval = RegOpenKeyEx(
  842. HKEY_LOCAL_MACHINE,
  843. TEXT( "Software\\Microsoft\\Exchange\\Client\\Extensions" ),
  844. 0,
  845. KEY_ALL_ACCESS,
  846. &hKeyCur
  847. );
  848. if (Rval == ERROR_SUCCESS) {
  849. RegDeleteValue( hKeyCur, TEXT( EXCHANGE_CLIENT_EXT_NAME ) );
  850. RegCloseKey( hKeyCur );
  851. }
  852. #ifdef MSFT_FAXVIEW
  853. ResetFileAssociation( FAXVIEW_EXTENSION, WANGIMAGE_ASSOC_NAME );
  854. ResetFileAssociation( FAXVIEW_EXTENSION2, WANGIMAGE_ASSOC_NAME );
  855. #endif
  856. //
  857. // unload the performance counters
  858. //
  859. hNull = CreateFile(
  860. TEXT("nul"),
  861. GENERIC_READ | GENERIC_WRITE,
  862. 0,
  863. NULL,
  864. OPEN_EXISTING,
  865. 0,
  866. NULL
  867. );
  868. if (hNull != INVALID_HANDLE_VALUE) {
  869. GetStartupInfo( &si );
  870. si.hStdInput = hNull;
  871. si.hStdOutput = hNull;
  872. si.hStdError = hNull;
  873. si.dwFlags = STARTF_USESTDHANDLES;
  874. _tcscpy( CmdLine, TEXT("unlodctr fax") );
  875. if (CreateProcess(
  876. NULL,
  877. CmdLine,
  878. NULL,
  879. NULL,
  880. TRUE,
  881. DETACHED_PROCESS,
  882. NULL,
  883. NULL,
  884. &si,
  885. &pi
  886. ))
  887. {
  888. WaitForSingleObject( pi.hProcess, INFINITE );
  889. CloseHandle( pi.hThread );
  890. CloseHandle( pi.hProcess );
  891. }
  892. CloseHandle( hNull );
  893. }
  894. return TRUE;
  895. }
  896. VOID
  897. DeleteModemRegistryKey(
  898. VOID
  899. )
  900. {
  901. HKEY hKeyDev;
  902. INT rVal;
  903. DWORD MaxSubKeyLen;
  904. LPTSTR KeyNameBuf;
  905. DWORD i;
  906. DWORD SubKeyLen;
  907. DWORD KeyNameLen;
  908. rVal = RegOpenKeyEx(
  909. HKEY_LOCAL_MACHINE,
  910. REGKEY_FAX_DEVICES,
  911. 0,
  912. KEY_ALL_ACCESS,
  913. &hKeyDev
  914. );
  915. if (rVal != ERROR_SUCCESS) {
  916. DebugPrint(( TEXT("Could not open devices registry key, ec=0x%08x"), rVal ));
  917. return;
  918. }
  919. MaxSubKeyLen = GetMaxSubKeyLen( hKeyDev );
  920. if (!MaxSubKeyLen) {
  921. return;
  922. }
  923. KeyNameLen =
  924. MaxSubKeyLen +
  925. sizeof(TCHAR) +
  926. _tcslen( REGKEY_MODEM ) +
  927. sizeof(TCHAR) +
  928. 32;
  929. KeyNameBuf = MemAlloc( KeyNameLen );
  930. if (KeyNameBuf == NULL) {
  931. DebugPrint(( TEXT("DeleteModemRegistryKey: MemAlloc failed" ) ));
  932. return;
  933. }
  934. rVal = ERROR_SUCCESS;
  935. i = 0;
  936. while (TRUE) {
  937. SubKeyLen = MaxSubKeyLen + sizeof(TCHAR);
  938. rVal = RegEnumKeyEx(
  939. hKeyDev,
  940. i++,
  941. KeyNameBuf,
  942. &SubKeyLen,
  943. NULL,
  944. NULL,
  945. NULL,
  946. NULL
  947. );
  948. if (rVal != ERROR_SUCCESS) {
  949. break;
  950. }
  951. _stprintf( &KeyNameBuf[SubKeyLen], TEXT( "\\%s") , REGKEY_MODEM );
  952. DeleteRegistryTree( hKeyDev, KeyNameBuf );
  953. };
  954. RegCloseKey( hKeyDev );
  955. }
  956. BOOL
  957. SetUnInstallInfo(
  958. VOID
  959. )
  960. {
  961. HKEY hKey;
  962. TCHAR UninstallString[MAX_PATH*2];
  963. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SETUP_UNINSTALL, TRUE, KEY_ALL_ACCESS );
  964. if (!hKey) {
  965. Assert(( ! TEXT("Could not open setup uninstall registry key") ));
  966. return FALSE;
  967. }
  968. if (!SetRegistryString( hKey, REGVAL_DISPLAY_NAME, GetProductName() )) {
  969. Assert(( ! TEXT("Could not set display name registry value") ));
  970. }
  971. ExpandEnvironmentStrings( UNINSTALL_STRING, UninstallString, sizeof(UninstallString) );
  972. if (!SetRegistryString( hKey, REGVAL_UNINSTALL_STRING, UninstallString )) {
  973. Assert(( ! TEXT("Could not set display name registry value") ));
  974. }
  975. RegCloseKey( hKey );
  976. return TRUE;
  977. }
  978. BOOL
  979. DeleteUnInstallInfo(
  980. VOID
  981. )
  982. {
  983. RegDeleteKey( HKEY_LOCAL_MACHINE, REGKEY_SETUP_UNINSTALL );
  984. return TRUE;
  985. }
  986. BOOL
  987. ResetFileAssociation(
  988. LPWSTR FileExtension,
  989. LPWSTR FileAssociationName
  990. )
  991. {
  992. HKEY hKey;
  993. hKey = OpenRegistryKey( HKEY_CLASSES_ROOT, FileExtension, TRUE, KEY_ALL_ACCESS );
  994. if (!hKey) {
  995. Assert(( ! TEXT("Could not open file extension registry key") ));
  996. return FALSE;
  997. }
  998. if (!SetRegistryString( hKey, NULL, FileAssociationName )) {
  999. Assert(( ! TEXT("Could not set file association name registry value") ));
  1000. }
  1001. RegCloseKey( hKey );
  1002. return TRUE;
  1003. }
  1004. BOOL
  1005. CreateFileAssociation(
  1006. LPWSTR FileExtension,
  1007. LPWSTR FileAssociationName,
  1008. LPWSTR FileAssociationDescription,
  1009. LPWSTR OpenCommand,
  1010. LPWSTR PrintCommand,
  1011. LPWSTR PrintToCommand,
  1012. LPWSTR FileName,
  1013. DWORD IconIndex
  1014. )
  1015. {
  1016. LONG rVal = 0;
  1017. HKEY hKey = NULL;
  1018. HKEY hKeyOpen = NULL;
  1019. HKEY hKeyPrint = NULL;
  1020. HKEY hKeyPrintTo = NULL;
  1021. HKEY hKeyIcon = NULL;
  1022. DWORD Disposition = 0;
  1023. WCHAR Buffer[MAX_PATH*2];
  1024. rVal = RegCreateKeyEx(
  1025. HKEY_CLASSES_ROOT,
  1026. FileExtension,
  1027. 0,
  1028. NULL,
  1029. 0,
  1030. KEY_ALL_ACCESS,
  1031. NULL,
  1032. &hKey,
  1033. &Disposition
  1034. );
  1035. if (rVal != ERROR_SUCCESS) {
  1036. goto exit;
  1037. }
  1038. rVal = RegSetValueEx(
  1039. hKey,
  1040. NULL,
  1041. 0,
  1042. REG_SZ,
  1043. (LPBYTE) FileAssociationName,
  1044. StringSize( FileAssociationName )
  1045. );
  1046. if (rVal != ERROR_SUCCESS) {
  1047. goto exit;
  1048. }
  1049. RegCloseKey( hKey );
  1050. rVal = RegCreateKeyEx(
  1051. HKEY_CLASSES_ROOT,
  1052. FileAssociationName,
  1053. 0,
  1054. NULL,
  1055. 0,
  1056. KEY_ALL_ACCESS,
  1057. NULL,
  1058. &hKey,
  1059. &Disposition
  1060. );
  1061. if (rVal != ERROR_SUCCESS) {
  1062. goto exit;
  1063. }
  1064. rVal = RegSetValueEx(
  1065. hKey,
  1066. NULL,
  1067. 0,
  1068. REG_SZ,
  1069. (LPBYTE) FileAssociationDescription,
  1070. StringSize( FileAssociationDescription )
  1071. );
  1072. if (rVal != ERROR_SUCCESS) {
  1073. goto exit;
  1074. }
  1075. rVal = RegCreateKeyEx(
  1076. hKey,
  1077. L"Shell\\Open\\Command",
  1078. 0,
  1079. NULL,
  1080. 0,
  1081. KEY_ALL_ACCESS,
  1082. NULL,
  1083. &hKeyOpen,
  1084. &Disposition
  1085. );
  1086. if (rVal != ERROR_SUCCESS) {
  1087. goto exit;
  1088. }
  1089. rVal = RegSetValueEx(
  1090. hKeyOpen,
  1091. NULL,
  1092. 0,
  1093. REG_EXPAND_SZ,
  1094. (LPBYTE) OpenCommand,
  1095. StringSize( OpenCommand )
  1096. );
  1097. if (rVal != ERROR_SUCCESS) {
  1098. goto exit;
  1099. }
  1100. if (PrintCommand) {
  1101. rVal = RegCreateKeyEx(
  1102. hKey,
  1103. L"Shell\\Print\\Command",
  1104. 0,
  1105. NULL,
  1106. 0,
  1107. KEY_ALL_ACCESS,
  1108. NULL,
  1109. &hKeyPrint,
  1110. &Disposition
  1111. );
  1112. if (rVal != ERROR_SUCCESS) {
  1113. goto exit;
  1114. }
  1115. rVal = RegSetValueEx(
  1116. hKeyPrint,
  1117. NULL,
  1118. 0,
  1119. REG_EXPAND_SZ,
  1120. (LPBYTE) PrintCommand,
  1121. StringSize( PrintCommand )
  1122. );
  1123. if (rVal != ERROR_SUCCESS) {
  1124. goto exit;
  1125. }
  1126. }
  1127. if (PrintToCommand) {
  1128. rVal = RegCreateKeyEx(
  1129. hKey,
  1130. L"Shell\\Printto\\Command",
  1131. 0,
  1132. NULL,
  1133. 0,
  1134. KEY_ALL_ACCESS,
  1135. NULL,
  1136. &hKeyPrintTo,
  1137. &Disposition
  1138. );
  1139. if (rVal != ERROR_SUCCESS) {
  1140. goto exit;
  1141. }
  1142. rVal = RegSetValueEx(
  1143. hKeyPrintTo,
  1144. NULL,
  1145. 0,
  1146. REG_EXPAND_SZ,
  1147. (LPBYTE) PrintToCommand,
  1148. StringSize( PrintToCommand )
  1149. );
  1150. if (rVal != ERROR_SUCCESS) {
  1151. goto exit;
  1152. }
  1153. }
  1154. if (FileName) {
  1155. rVal = RegCreateKeyEx(
  1156. hKey,
  1157. L"DefaultIcon",
  1158. 0,
  1159. NULL,
  1160. 0,
  1161. KEY_ALL_ACCESS,
  1162. NULL,
  1163. &hKeyIcon,
  1164. &Disposition
  1165. );
  1166. if (rVal != ERROR_SUCCESS) {
  1167. goto exit;
  1168. }
  1169. wsprintf( Buffer, L"%s,%d", FileName, IconIndex );
  1170. rVal = RegSetValueEx(
  1171. hKeyIcon,
  1172. NULL,
  1173. 0,
  1174. REG_EXPAND_SZ,
  1175. (LPBYTE) Buffer,
  1176. StringSize( Buffer )
  1177. );
  1178. if (rVal != ERROR_SUCCESS) {
  1179. goto exit;
  1180. }
  1181. }
  1182. exit:
  1183. RegCloseKey( hKey );
  1184. RegCloseKey( hKeyOpen );
  1185. RegCloseKey( hKeyPrint );
  1186. RegCloseKey( hKeyPrintTo );
  1187. RegCloseKey( hKeyIcon );
  1188. return rVal == ERROR_SUCCESS;
  1189. }
  1190. BOOL
  1191. IsWordpadInstalled(
  1192. VOID
  1193. )
  1194. {
  1195. HKEY hKey;
  1196. LONG rVal;
  1197. DWORD RegType;
  1198. DWORD RegSize;
  1199. TCHAR Data[16];
  1200. rVal = RegOpenKey(
  1201. HKEY_LOCAL_MACHINE,
  1202. REGKEY_WORDPAD,
  1203. &hKey
  1204. );
  1205. if (rVal != ERROR_SUCCESS) {
  1206. DebugPrint(( TEXT("Could not open wordpad registry key, ec=0x%08x"), rVal ));
  1207. return FALSE;
  1208. }
  1209. RegSize = sizeof(Data);
  1210. rVal = RegQueryValueEx(
  1211. hKey,
  1212. REGVAL_WP_INSTALLED,
  1213. 0,
  1214. &RegType,
  1215. (LPBYTE) Data,
  1216. &RegSize
  1217. );
  1218. if (rVal != ERROR_SUCCESS) {
  1219. DebugPrint(( TEXT("Could not query wordpad installed registry value, ec=0x%08x"), rVal ));
  1220. Data[0] = 0;
  1221. }
  1222. RegCloseKey( hKey );
  1223. if (_tcscmp( Data, TEXT("1") ) == 0) {
  1224. return TRUE;
  1225. }
  1226. return FALSE;
  1227. }
  1228. BOOL
  1229. InstallWordpad(
  1230. VOID
  1231. )
  1232. {
  1233. HKEY hKey;
  1234. LONG rVal;
  1235. DWORD RegType;
  1236. DWORD RegSize;
  1237. TCHAR InfName[32];
  1238. TCHAR SectionName[32];
  1239. TCHAR Command[256];
  1240. STARTUPINFO si;
  1241. PROCESS_INFORMATION pi;
  1242. DWORD ExitCode;
  1243. rVal = RegOpenKey(
  1244. HKEY_LOCAL_MACHINE,
  1245. REGKEY_WORDPAD,
  1246. &hKey
  1247. );
  1248. if (rVal != ERROR_SUCCESS) {
  1249. DebugPrint(( TEXT("Could not open wordpad registry key, ec=0x%08x"), rVal ));
  1250. return FALSE;
  1251. }
  1252. RegSize = sizeof(InfName);
  1253. rVal = RegQueryValueEx(
  1254. hKey,
  1255. REGVAL_WP_INF,
  1256. 0,
  1257. &RegType,
  1258. (LPBYTE) InfName,
  1259. &RegSize
  1260. );
  1261. if (rVal != ERROR_SUCCESS) {
  1262. DebugPrint(( TEXT("Could not query wordpad inf name registry value, ec=0x%08x"), rVal ));
  1263. InfName[0] = 0;
  1264. }
  1265. RegSize = sizeof(SectionName);
  1266. rVal = RegQueryValueEx(
  1267. hKey,
  1268. REGVAL_WP_SECTION,
  1269. 0,
  1270. &RegType,
  1271. (LPBYTE) SectionName,
  1272. &RegSize
  1273. );
  1274. if (rVal != ERROR_SUCCESS) {
  1275. DebugPrint(( TEXT("Could not query wordpad inf name registry value, ec=0x%08x"), rVal ));
  1276. SectionName[0] = 0;
  1277. }
  1278. RegCloseKey( hKey );
  1279. if (InfName[0] == 0 || SectionName[0] == 0) {
  1280. return FALSE;
  1281. }
  1282. _stprintf( Command, RUNDLL32_INF_INSTALL_CMD, SectionName, InfName );
  1283. GetStartupInfo( &si );
  1284. rVal = CreateProcess(
  1285. NULL,
  1286. Command,
  1287. NULL,
  1288. NULL,
  1289. FALSE,
  1290. 0,
  1291. NULL,
  1292. NULL,
  1293. &si,
  1294. &pi
  1295. );
  1296. if (rVal) {
  1297. WaitForSingleObject( pi.hProcess, INFINITE );
  1298. if (GetExitCodeProcess( pi.hProcess, &ExitCode ) && ExitCode == 0) {
  1299. return TRUE;
  1300. }
  1301. }
  1302. return FALSE;
  1303. }
  1304. BOOL
  1305. ChangeTxtFileAssociation(
  1306. VOID
  1307. )
  1308. {
  1309. LONG rVal = 0;
  1310. HKEY hKey = NULL;
  1311. HKEY hKeyCmd = NULL;
  1312. DWORD Disposition = 0;
  1313. DeleteRegistryTree( HKEY_CLASSES_ROOT, TEXT("txtfile\\shell") );
  1314. rVal = RegOpenKey(
  1315. HKEY_CLASSES_ROOT,
  1316. TEXT("txtfile"),
  1317. &hKey
  1318. );
  1319. if (rVal != ERROR_SUCCESS) {
  1320. DebugPrint(( TEXT("Could not open wordpad registry key, ec=0x%08x"), rVal ));
  1321. return FALSE;
  1322. }
  1323. rVal = RegCreateKeyEx(
  1324. hKey,
  1325. TEXT("shell\\open\\command"),
  1326. 0,
  1327. NULL,
  1328. 0,
  1329. KEY_ALL_ACCESS,
  1330. NULL,
  1331. &hKeyCmd,
  1332. &Disposition
  1333. );
  1334. if (rVal != ERROR_SUCCESS) {
  1335. goto exit;
  1336. }
  1337. rVal = RegSetValueEx(
  1338. hKeyCmd,
  1339. NULL,
  1340. 0,
  1341. REG_EXPAND_SZ,
  1342. (LPBYTE) WORDPAD_OPEN_CMD,
  1343. StringSize( WORDPAD_OPEN_CMD )
  1344. );
  1345. if (rVal != ERROR_SUCCESS) {
  1346. goto exit;
  1347. }
  1348. RegCloseKey( hKeyCmd );
  1349. rVal = RegCreateKeyEx(
  1350. hKey,
  1351. TEXT("shell\\print\\command"),
  1352. 0,
  1353. NULL,
  1354. 0,
  1355. KEY_ALL_ACCESS,
  1356. NULL,
  1357. &hKeyCmd,
  1358. &Disposition
  1359. );
  1360. if (rVal != ERROR_SUCCESS) {
  1361. goto exit;
  1362. }
  1363. rVal = RegSetValueEx(
  1364. hKeyCmd,
  1365. NULL,
  1366. 0,
  1367. REG_EXPAND_SZ,
  1368. (LPBYTE) WORDPAD_PRINT_CMD,
  1369. StringSize( WORDPAD_PRINT_CMD )
  1370. );
  1371. if (rVal != ERROR_SUCCESS) {
  1372. goto exit;
  1373. }
  1374. RegCloseKey( hKeyCmd );
  1375. rVal = RegCreateKeyEx(
  1376. hKey,
  1377. TEXT("shell\\printto\\command"),
  1378. 0,
  1379. NULL,
  1380. 0,
  1381. KEY_ALL_ACCESS,
  1382. NULL,
  1383. &hKeyCmd,
  1384. &Disposition
  1385. );
  1386. if (rVal != ERROR_SUCCESS) {
  1387. goto exit;
  1388. }
  1389. rVal = RegSetValueEx(
  1390. hKeyCmd,
  1391. NULL,
  1392. 0,
  1393. REG_EXPAND_SZ,
  1394. (LPBYTE) WORDPAD_PRINTTO_CMD,
  1395. StringSize( WORDPAD_PRINTTO_CMD )
  1396. );
  1397. if (rVal != ERROR_SUCCESS) {
  1398. goto exit;
  1399. }
  1400. RegCloseKey( hKeyCmd );
  1401. exit:
  1402. RegCloseKey( hKey );
  1403. return TRUE;
  1404. }