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.

1490 lines
37 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 "faxocm.h"
  13. #pragma hdrstop
  14. BOOL
  15. CreateDeviceProvider(
  16. HKEY hKey,
  17. LPWSTR ProviderKey,
  18. LPWSTR FriendlyName,
  19. LPWSTR ImageName,
  20. LPWSTR ProviderName
  21. )
  22. {
  23. hKey = OpenRegistryKey( hKey, ProviderKey, TRUE, KEY_ALL_ACCESS );
  24. if (!hKey) {
  25. DebugPrint(( L"could not create/open registry key (test)" ));
  26. return FALSE;
  27. }
  28. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  29. DebugPrint(( L"could not add friendly name value" ));
  30. return FALSE;
  31. }
  32. if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) {
  33. DebugPrint(( L"could not add image name value" ));
  34. return FALSE;
  35. }
  36. if (!SetRegistryString( hKey, REGVAL_PROVIDER_NAME, ProviderName )) {
  37. DebugPrint(( L"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. LPWSTR MethodName,
  47. LPWSTR FunctionName,
  48. LPWSTR FriendlyName,
  49. LPWSTR Guid,
  50. DWORD Priority
  51. )
  52. {
  53. hKey = OpenRegistryKey( hKey, MethodName, TRUE, KEY_ALL_ACCESS );
  54. if (!hKey) {
  55. DebugPrint(( L"could not create/open registry key for routing method" ));
  56. return FALSE;
  57. }
  58. if (!SetRegistryString( hKey, REGVAL_FUNCTION_NAME, FunctionName )) {
  59. DebugPrint(( L"could not add function name value" ));
  60. return FALSE;
  61. }
  62. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  63. DebugPrint(( L"could not add friendly name value" ));
  64. return FALSE;
  65. }
  66. if (!SetRegistryString( hKey, REGVAL_GUID, Guid )) {
  67. DebugPrint(( L"could not add function name value" ));
  68. return FALSE;
  69. }
  70. if (!SetRegistryDword( hKey, REGVAL_ROUTING_PRIORITY, Priority )) {
  71. DebugPrint(( L"Could not set priority registry value" ));
  72. }
  73. RegCloseKey( hKey );
  74. return TRUE;
  75. }
  76. BOOL
  77. CreateMicrosoftRoutingExtension(
  78. HKEY hKey,
  79. LPWSTR RoutingKey,
  80. LPWSTR FriendlyName,
  81. LPWSTR ImageName
  82. )
  83. {
  84. HKEY hKeyMethods;
  85. hKey = OpenRegistryKey( hKey, RoutingKey, TRUE, KEY_ALL_ACCESS );
  86. if (!hKey) {
  87. DebugPrint(( L"could not create/open registry key for routing extension" ));
  88. return FALSE;
  89. }
  90. if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) {
  91. DebugPrint(( L"could not add friendly name value" ));
  92. return FALSE;
  93. }
  94. if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) {
  95. DebugPrint(( L"could not add image name value" ));
  96. return FALSE;
  97. }
  98. hKeyMethods = OpenRegistryKey( hKey, REGKEY_ROUTING_METHODS, TRUE, KEY_ALL_ACCESS );
  99. if (!hKeyMethods) {
  100. DebugPrint(( L"could not create/open registry key for routing methods" ));
  101. return FALSE;
  102. }
  103. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_EMAIL, REGVAL_RM_EMAIL_FUNCTION, GetString(IDS_RT_EMAIL_FRIENDLY), REGVAL_RM_EMAIL_GUID, 4 );
  104. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_FOLDER, REGVAL_RM_FOLDER_FUNCTION, GetString(IDS_RT_FOLDER_FRIENDLY), REGVAL_RM_FOLDER_GUID, 1 );
  105. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_INBOX, REGVAL_RM_INBOX_FUNCTION, GetString(IDS_RT_INBOX_FRIENDLY), REGVAL_RM_INBOX_GUID, 3 );
  106. CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_PRINTING, REGVAL_RM_PRINTING_FUNCTION, GetString(IDS_RT_PRINT_FRIENDLY), REGVAL_RM_PRINTING_GUID, 2 );
  107. RegCloseKey( hKeyMethods );
  108. RegCloseKey( hKey );
  109. return TRUE;
  110. }
  111. VOID
  112. RegCreateFaxDevice(
  113. HKEY hKeyDev,
  114. DWORD PermanentLineID,
  115. DWORD Rings,
  116. DWORD Priority,
  117. DWORD Flags,
  118. LPWSTR DeviceName,
  119. LPWSTR ProviderName,
  120. LPWSTR Csid,
  121. LPWSTR Tsid,
  122. DWORD RoutingMask,
  123. LPWSTR RoutePrinterName,
  124. LPWSTR RouteDir,
  125. LPWSTR RouteProfile
  126. )
  127. {
  128. HKEY hKey;
  129. HKEY hKeyRouting;
  130. WCHAR PortName[32];
  131. swprintf( PortName, L"%08d", PermanentLineID );
  132. hKey = OpenRegistryKey( hKeyDev, PortName, TRUE, KEY_ALL_ACCESS );
  133. if (!hKey) {
  134. DebugPrint(( L"Could not open device registry key" ));
  135. return;
  136. }
  137. if (!SetRegistryDword( hKey, REGVAL_PERMANENT_LINEID, PermanentLineID )) {
  138. DebugPrint(( L"Could not set device id registry value" ));
  139. }
  140. if (!SetRegistryDword( hKey, REGVAL_FLAGS, Flags )) {
  141. DebugPrint(( L"Could not set device flags registry value" ));
  142. }
  143. if (!SetRegistryDword( hKey, REGVAL_RINGS, Rings )) {
  144. DebugPrint(( L"Could not set device rings registry value" ));
  145. }
  146. if (!SetRegistryDword( hKey, REGVAL_PRIORITY, Priority )) {
  147. DebugPrint(( L"Could not set device rings registry value" ));
  148. }
  149. if (!SetRegistryString( hKey, REGVAL_DEVICE_NAME, DeviceName )) {
  150. DebugPrint(( L"Could not set device name registry value" ));
  151. }
  152. if (!SetRegistryString( hKey, REGVAL_PROVIDER, ProviderName )) {
  153. DebugPrint(( L"Could not set provider name registry value" ));
  154. }
  155. if (!SetRegistryString( hKey, REGVAL_ROUTING_CSID, Csid )) {
  156. DebugPrint(( L"Could not set csid registry value" ));
  157. }
  158. if (!SetRegistryString( hKey, REGVAL_ROUTING_TSID, Tsid )) {
  159. DebugPrint(( L"Could not set csid registry value" ));
  160. }
  161. hKeyRouting = OpenRegistryKey( hKey, REGKEY_ROUTING, TRUE, KEY_ALL_ACCESS );
  162. if (!hKeyRouting) {
  163. DebugPrint(( L"Could not open routing registry key" ));
  164. return;
  165. }
  166. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PRINTER, RoutePrinterName )) {
  167. DebugPrint(( L"Could not set printer name registry value" ));
  168. }
  169. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_DIR, RouteDir )) {
  170. DebugPrint(( L"Could not set routing dir registry value" ));
  171. }
  172. if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PROFILE, RouteProfile )) {
  173. DebugPrint(( L"Could not set routing profile name registry value" ));
  174. }
  175. if (!SetRegistryDword( hKeyRouting, REGVAL_ROUTING_MASK, RoutingMask )) {
  176. DebugPrint(( L"Could not set routing mask registry value" ));
  177. }
  178. RegCloseKey( hKeyRouting );
  179. RegCloseKey( hKey );
  180. }
  181. BOOL
  182. CreateFileAssociation(
  183. LPWSTR FileExtension,
  184. LPWSTR FileAssociationName,
  185. LPWSTR FileAssociationDescription,
  186. LPWSTR OpenCommand,
  187. LPWSTR PrintCommand,
  188. LPWSTR PrintToCommand,
  189. LPWSTR FileName,
  190. DWORD IconIndex
  191. )
  192. {
  193. LONG rVal = 0;
  194. HKEY hKey = NULL;
  195. HKEY hKeyOpen = NULL;
  196. HKEY hKeyPrint = NULL;
  197. HKEY hKeyPrintTo = NULL;
  198. HKEY hKeyIcon = NULL;
  199. DWORD Disposition = 0;
  200. WCHAR Buffer[MAX_PATH*2];
  201. rVal = RegCreateKeyEx(
  202. HKEY_CLASSES_ROOT,
  203. FileExtension,
  204. 0,
  205. NULL,
  206. 0,
  207. KEY_ALL_ACCESS,
  208. NULL,
  209. &hKey,
  210. &Disposition
  211. );
  212. if (rVal != ERROR_SUCCESS) {
  213. goto exit;
  214. }
  215. rVal = RegSetValueEx(
  216. hKey,
  217. NULL,
  218. 0,
  219. REG_SZ,
  220. (LPBYTE) FileAssociationName,
  221. StringSize( FileAssociationName )
  222. );
  223. if (rVal != ERROR_SUCCESS) {
  224. goto exit;
  225. }
  226. RegCloseKey( hKey );
  227. rVal = RegCreateKeyEx(
  228. HKEY_CLASSES_ROOT,
  229. FileAssociationName,
  230. 0,
  231. NULL,
  232. 0,
  233. KEY_ALL_ACCESS,
  234. NULL,
  235. &hKey,
  236. &Disposition
  237. );
  238. if (rVal != ERROR_SUCCESS) {
  239. goto exit;
  240. }
  241. rVal = RegSetValueEx(
  242. hKey,
  243. NULL,
  244. 0,
  245. REG_SZ,
  246. (LPBYTE) FileAssociationDescription,
  247. StringSize( FileAssociationDescription )
  248. );
  249. if (rVal != ERROR_SUCCESS) {
  250. goto exit;
  251. }
  252. rVal = RegCreateKeyEx(
  253. hKey,
  254. L"Shell\\Open\\Command",
  255. 0,
  256. NULL,
  257. 0,
  258. KEY_ALL_ACCESS,
  259. NULL,
  260. &hKeyOpen,
  261. &Disposition
  262. );
  263. if (rVal != ERROR_SUCCESS) {
  264. goto exit;
  265. }
  266. rVal = RegSetValueEx(
  267. hKeyOpen,
  268. NULL,
  269. 0,
  270. REG_EXPAND_SZ,
  271. (LPBYTE) OpenCommand,
  272. StringSize( OpenCommand )
  273. );
  274. if (rVal != ERROR_SUCCESS) {
  275. goto exit;
  276. }
  277. if (PrintCommand) {
  278. rVal = RegCreateKeyEx(
  279. hKey,
  280. L"Shell\\Print\\Command",
  281. 0,
  282. NULL,
  283. 0,
  284. KEY_ALL_ACCESS,
  285. NULL,
  286. &hKeyPrint,
  287. &Disposition
  288. );
  289. if (rVal != ERROR_SUCCESS) {
  290. goto exit;
  291. }
  292. rVal = RegSetValueEx(
  293. hKeyPrint,
  294. NULL,
  295. 0,
  296. REG_EXPAND_SZ,
  297. (LPBYTE) PrintCommand,
  298. StringSize( PrintCommand )
  299. );
  300. if (rVal != ERROR_SUCCESS) {
  301. goto exit;
  302. }
  303. }
  304. if (PrintToCommand) {
  305. rVal = RegCreateKeyEx(
  306. hKey,
  307. L"Shell\\Printto\\Command",
  308. 0,
  309. NULL,
  310. 0,
  311. KEY_ALL_ACCESS,
  312. NULL,
  313. &hKeyPrintTo,
  314. &Disposition
  315. );
  316. if (rVal != ERROR_SUCCESS) {
  317. goto exit;
  318. }
  319. rVal = RegSetValueEx(
  320. hKeyPrintTo,
  321. NULL,
  322. 0,
  323. REG_EXPAND_SZ,
  324. (LPBYTE) PrintToCommand,
  325. StringSize( PrintToCommand )
  326. );
  327. if (rVal != ERROR_SUCCESS) {
  328. goto exit;
  329. }
  330. }
  331. if (FileName) {
  332. rVal = RegCreateKeyEx(
  333. hKey,
  334. L"DefaultIcon",
  335. 0,
  336. NULL,
  337. 0,
  338. KEY_ALL_ACCESS,
  339. NULL,
  340. &hKeyIcon,
  341. &Disposition
  342. );
  343. if (rVal != ERROR_SUCCESS) {
  344. goto exit;
  345. }
  346. wsprintf( Buffer, L"%s,%d", FileName, IconIndex );
  347. rVal = RegSetValueEx(
  348. hKeyIcon,
  349. NULL,
  350. 0,
  351. REG_EXPAND_SZ,
  352. (LPBYTE) Buffer,
  353. StringSize( Buffer )
  354. );
  355. if (rVal != ERROR_SUCCESS) {
  356. goto exit;
  357. }
  358. }
  359. exit:
  360. RegCloseKey( hKey );
  361. RegCloseKey( hKeyOpen );
  362. RegCloseKey( hKeyPrint );
  363. RegCloseKey( hKeyPrintTo );
  364. RegCloseKey( hKeyIcon );
  365. return rVal == ERROR_SUCCESS;
  366. }
  367. BOOL
  368. SetServerRegistryData(
  369. LPWSTR SourceRoot
  370. )
  371. {
  372. HKEY hKey;
  373. LONG rVal;
  374. DWORD i;
  375. HKEY hKeyDev;
  376. HANDLE hNull;
  377. STARTUPINFO si;
  378. PROCESS_INFORMATION pi;
  379. WCHAR CmdLine[128];
  380. LPWSTR LodCmdLine;
  381. LPWSTR LodSrcPath;
  382. //
  383. // set top level defaults
  384. //
  385. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS );
  386. if (!hKey) {
  387. DebugPrint(( L"Could not open software registry key" ));
  388. return FALSE;
  389. }
  390. if (!Upgrade) {
  391. if (!SetKeySecurity(hKey) ) {
  392. DebugPrint(( L"Couldn't set key security" ));
  393. return FALSE;
  394. }
  395. }
  396. if (!Upgrade) {
  397. if (!SetRegistryDword( hKey, REGVAL_RETRIES, DEFAULT_REGVAL_RETRIES )) {
  398. DebugPrint(( L"Could not set retries registry value" ));
  399. }
  400. if (!SetRegistryDword( hKey, REGVAL_RETRYDELAY, DEFAULT_REGVAL_RETRYDELAY )) {
  401. DebugPrint(( L"Could not set retry delay registry value" ));
  402. }
  403. if (!SetRegistryDword( hKey, REGVAL_DIRTYDAYS, DEFAULT_REGVAL_DIRTYDAYS )) {
  404. DebugPrint(( L"Could not set dirty days registry value" ));
  405. }
  406. if (!SetRegistryDword( hKey, REGVAL_QUEUE_PAUSED, DEFAULT_REGVAL_QUEUE_PAUSED )) {
  407. DebugPrint(( L"Could not set queue paused registry value" ));
  408. }
  409. if (!SetRegistryDword( hKey, REGVAL_JOB_NUMBER, DEFAULT_REGVAL_JOB_NUMBER )) {
  410. DebugPrint(( L"Could not net job number registry value" ));
  411. }
  412. if (!SetRegistryDword( hKey, REGVAL_BRANDING, DEFAULT_REGVAL_BRANDING )) {
  413. DebugPrint(( L"Could not set branding registry value" ));
  414. }
  415. if (!SetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID, DEFAULT_REGVAL_USEDEVICETSID )) {
  416. DebugPrint(( L"Could not set usedevicetsid registry value" ));
  417. }
  418. if (!SetRegistryString( hKey, REGVAL_INBOUND_PROFILE, EMPTY_STRING )) {
  419. DebugPrint(( L"Could not set inbound profile registry value" ));
  420. }
  421. if (!SetRegistryDword( hKey, REGVAL_SERVERCP, DEFAULT_REGVAL_SERVERCP )) {
  422. DebugPrint(( L"Could not set servercp registry value" ));
  423. }
  424. if (!SetRegistryDword( hKey, REGVAL_STARTCHEAP, DEFAULT_REGVAL_STARTCHEAP )) {
  425. DebugPrint(( L"Could not set startcheap registry value" ));
  426. }
  427. if (!SetRegistryDword( hKey, REGVAL_STOPCHEAP, DEFAULT_REGVAL_STOPCHEAP )) {
  428. DebugPrint(( L"Could not set stopcheap registry value" ));
  429. }
  430. if (WizData.ArchiveOutgoing) {
  431. if (!SetRegistryDword( hKey, REGVAL_ARCHIVEFLAG, 1 )) {
  432. DebugPrint(( L"Could not set archiveflag registry value" ));
  433. }
  434. if (!SetRegistryString( hKey, REGVAL_ARCHIVEDIR, WizData.ArchiveDir )) {
  435. DebugPrint(( L"Could not set archive dir registry value" ));
  436. }
  437. }
  438. RegCloseKey( hKey );
  439. }
  440. if (!Upgrade) {
  441. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_DEVICES, TRUE, KEY_ALL_ACCESS );
  442. if (!hKey) {
  443. DebugPrint(( L"Could not open devices registry key" ));
  444. return FALSE;
  445. }
  446. //
  447. // enumerate the devices and create the registry data
  448. //
  449. for (i=0; i<FaxDevices; i++) {
  450. RegCreateFaxDevice(
  451. hKeyDev,
  452. LineInfo[i].PermanentLineID,
  453. LineInfo[i].Rings,
  454. i+1,
  455. LineInfo[i].Flags,
  456. LineInfo[i].DeviceName,
  457. LineInfo[i].ProviderName,
  458. WizData.Csid,
  459. WizData.Tsid,
  460. WizData.RoutingMask,
  461. WizData.RoutePrinterName,
  462. WizData.RouteDir,
  463. WizData.RouteProfile
  464. );
  465. }
  466. RegCloseKey( hKeyDev );
  467. }
  468. //
  469. // create the device providers
  470. //
  471. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_DEVICE_PROVIDER_KEY, TRUE, KEY_ALL_ACCESS );
  472. if (!hKeyDev) {
  473. DebugPrint(( L"Could not open device provider registry key" ));
  474. return FALSE;
  475. }
  476. CreateDeviceProvider(
  477. hKeyDev,
  478. REGKEY_MODEM_PROVIDER,
  479. REGVAL_MODEM_FRIENDLY_NAME_TEXT,
  480. REGVAL_MODEM_IMAGE_NAME_TEXT,
  481. GetString(IDS_MODEM_PROVIDER_NAME)
  482. );
  483. RegCloseKey( hKeyDev );
  484. //
  485. // create the routing extensions
  486. //
  487. hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_ROUTING_EXTENSION_KEY, TRUE, KEY_ALL_ACCESS );
  488. if (!hKeyDev) {
  489. DebugPrint(( L"Could not open routing extension registry key" ));
  490. return FALSE;
  491. }
  492. CreateMicrosoftRoutingExtension(
  493. hKeyDev,
  494. REGKEY_ROUTING_EXTENSION,
  495. REGVAL_ROUTE_FRIENDLY_NAME,
  496. REGVAL_ROUTE_IMAGE_NAME
  497. );
  498. RegCloseKey( hKeyDev );
  499. //
  500. // set the co-class installer
  501. //
  502. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_CODEVICEINSTALLERS, TRUE, KEY_ALL_ACCESS );
  503. if (hKey) {
  504. DWORD Size;
  505. LPWSTR Class = GetRegistryStringMultiSz( hKey, REGVAL_MODEM_CODEVICE, EMPTY_STRING, &Size );
  506. if (Class) {
  507. LPWSTR p = Class;
  508. BOOL Found = FALSE;
  509. while (p && *p) {
  510. if (_wcsicmp( p, FAX_COCLASS_STRING ) == 0) {
  511. Found = TRUE;
  512. break;
  513. }
  514. p += (wcslen(p) + 1);
  515. }
  516. if (!Found) {
  517. LPBYTE NewClass = (LPBYTE) MemAlloc( StringSize(Class) + StringSize(FAX_COCLASS_STRING) + 16 );
  518. if (NewClass) {
  519. CopyMemory( NewClass, Class, Size );
  520. wcscpy( (LPWSTR)(NewClass+Size-sizeof(WCHAR)), FAX_COCLASS_STRING );
  521. Size += StringSize(FAX_COCLASS_STRING);
  522. SetRegistryStringMultiSz( hKey, REGVAL_MODEM_CODEVICE, (LPWSTR) NewClass, Size );
  523. MemFree( NewClass );
  524. }
  525. }
  526. MemFree( Class );
  527. }
  528. RegCloseKey( hKey );
  529. }
  530. //
  531. // set the user's preferences
  532. //
  533. if (!Upgrade) {
  534. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  535. if (!hKey) {
  536. DebugPrint(( L"Could not open fax setup registry key" ));
  537. return FALSE;
  538. }
  539. if (!SetRegistryStringExpand( hKey, REGVAL_CP_LOCATION, GetString(IDS_PERSONAL_COVERPAGE) )) {
  540. DebugPrint(( L"Could not set coverpage dir registry value" ));
  541. }
  542. if (!SetRegistryString( hKey, REGVAL_CP_EDITOR, COVERPAGE_EDITOR )) {
  543. DebugPrint(( L"Could not set coverpage editor registry value" ));
  544. }
  545. RegCloseKey( hKey );
  546. }
  547. //
  548. // create the perfmon registry data
  549. //
  550. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAXPERF, TRUE, KEY_ALL_ACCESS );
  551. if (!hKey) {
  552. DebugPrint(( L"Could not open fax perfmon registry key" ));
  553. return FALSE;
  554. }
  555. if (!SetRegistryStringExpand( hKey, REGVAL_OPEN, REGVAL_OPEN_DATA )) {
  556. DebugPrint(( L"Could not set perfmon registry value" ));
  557. }
  558. if (!SetRegistryStringExpand( hKey, REGVAL_CLOSE, REGVAL_CLOSE_DATA )) {
  559. DebugPrint(( L"Could not set perfmon registry value" ));
  560. }
  561. if (!SetRegistryStringExpand( hKey, REGVAL_COLLECT, REGVAL_COLLECT_DATA )) {
  562. DebugPrint(( L"Could not set perfmon registry value" ));
  563. }
  564. if (!SetRegistryStringExpand( hKey, REGVAL_LIBRARY, REGVAL_LIBRARY_DATA )) {
  565. DebugPrint(( L"Could not set perfmon registry value" ));
  566. }
  567. RegCloseKey( hKey );
  568. //
  569. // load the performance counters
  570. //
  571. hNull = CreateFile(
  572. L"nul",
  573. GENERIC_READ | GENERIC_WRITE,
  574. 0,
  575. NULL,
  576. OPEN_EXISTING,
  577. 0,
  578. NULL
  579. );
  580. if (hNull == INVALID_HANDLE_VALUE) {
  581. rVal = GetLastError();
  582. return FALSE;
  583. }
  584. GetStartupInfo( &si );
  585. si.hStdInput = hNull;
  586. si.hStdOutput = hNull;
  587. si.hStdError = hNull;
  588. si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  589. si.wShowWindow = SW_HIDE;
  590. wcscpy( CmdLine, L"unlodctr fax" );
  591. rVal = CreateProcess(
  592. NULL,
  593. CmdLine,
  594. NULL,
  595. NULL,
  596. TRUE,
  597. DETACHED_PROCESS,
  598. NULL,
  599. NULL,
  600. &si,
  601. &pi
  602. );
  603. if (!rVal) {
  604. rVal = GetLastError();
  605. return FALSE;
  606. }
  607. WaitForSingleObject( pi.hProcess, INFINITE );
  608. CloseHandle( pi.hProcess );
  609. CloseHandle( pi.hThread );
  610. if (NtGuiMode) {
  611. LodCmdLine = ExpandEnvironmentString( L"lodctr %systemroot%\\system32\\faxperf.ini" );
  612. if (!LodCmdLine) {
  613. return FALSE;
  614. }
  615. } else {
  616. LodCmdLine = L"lodctr faxperf.ini";
  617. LodSrcPath = ExpandEnvironmentString( L"%systemroot%\\system32\\" );
  618. }
  619. wcscpy( CmdLine, LodCmdLine );
  620. rVal = CreateProcess(
  621. NULL,
  622. CmdLine,
  623. NULL,
  624. NULL,
  625. TRUE,
  626. DETACHED_PROCESS,
  627. NULL,
  628. NtGuiMode ? NULL : LodSrcPath,
  629. &si,
  630. &pi
  631. );
  632. if (!rVal) {
  633. rVal = GetLastError();
  634. return FALSE;
  635. }
  636. WaitForSingleObject( pi.hProcess, INFINITE );
  637. CloseHandle( pi.hProcess );
  638. CloseHandle( pi.hThread );
  639. CloseHandle( hNull );
  640. CreateFileAssociation(
  641. COVERPAGE_EXTENSION,
  642. GetString(IDS_COVERPAGE),
  643. GetString(IDS_COVERPAGEDESC),
  644. COVERPAGE_OPEN_COMMAND,
  645. COVERPAGE_PRINT_COMMAND,
  646. NULL,
  647. NULL,
  648. 0
  649. );
  650. return TRUE;
  651. }
  652. BOOL
  653. SetClientRegistryData(
  654. VOID
  655. )
  656. {
  657. HKEY hKey;
  658. if (!Upgrade) {
  659. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_USERINFO, TRUE, KEY_ALL_ACCESS );
  660. if (!hKey) {
  661. DebugPrint(( L"Could not open fax user info registry key" ));
  662. return FALSE;
  663. }
  664. if (!SetRegistryString( hKey, REGVAL_FULLNAME, WizData.UserName )) {
  665. DebugPrint(( L"Could not set user name registry value" ));
  666. }
  667. if (!SetRegistryString( hKey, REGVAL_FAX_NUMBER, WizData.PhoneNumber )) {
  668. DebugPrint(( L"Could not set fax phone number registry value" ));
  669. }
  670. if (!SetRegistryDword( hKey, REGVAL_LAST_COUNTRYID, CurrentCountryId )) {
  671. DebugPrint(( L"Could not set last country id registry value" ));
  672. }
  673. if (!SetRegistryDword( hKey, REGVAL_USE_DIALING_RULES, 0 )) {
  674. DebugPrint(( L"Could not set use dialing rules registry value" ));
  675. }
  676. if (!SetRegistryDword( hKey, REGVAL_ALWAYS_ON_TOP, BST_UNCHECKED )) {
  677. DebugPrint(( L"Could not set always on top registry value" ));
  678. }
  679. if (!SetRegistryDword( hKey, REGVAL_SOUND_NOTIFICATION, BST_UNCHECKED )) {
  680. DebugPrint(( L"Could not set sound notification registry value" ));
  681. }
  682. if (!SetRegistryDword( hKey, REGVAL_ENABLE_MANUAL_ANSWER, BST_UNCHECKED )) {
  683. DebugPrint(( L"Could not set enable manual answer registry value" ));
  684. }
  685. if (!SetRegistryDword( hKey, REGVAL_TASKBAR, BST_CHECKED )) {
  686. DebugPrint(( L"Could not set enable manual answer registry value" ));
  687. }
  688. if (!SetRegistryDword( hKey, REGVAL_VISUAL_NOTIFICATION, BST_CHECKED )) {
  689. DebugPrint(( L"Could not set visual notification registry value" ));
  690. }
  691. if (!SetRegistryString( hKey, REGVAL_LAST_RECAREACODE, CurrentAreaCode )) {
  692. DebugPrint(( L"Could not set area code registry value" ));
  693. }
  694. RegCloseKey( hKey );
  695. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  696. if (!hKey) {
  697. DebugPrint(( L"Could not open fax setup registry key" ));
  698. return FALSE;
  699. }
  700. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED, TRUE )) {
  701. DebugPrint(( L"Could not set installed registry value" ));
  702. }
  703. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE, FAX_INSTALL_NETWORK_CLIENT )) {
  704. DebugPrint(( L"Could not set install type registry value" ));
  705. }
  706. if (!SetRegistryStringExpand( hKey, REGVAL_CP_LOCATION, GetString(IDS_PERSONAL_COVERPAGE) )) {
  707. DebugPrint(( L"Could not set coverpage dir registry value" ));
  708. }
  709. if (!SetRegistryStringExpand( hKey, REGVAL_CP_EDITOR, COVERPAGE_EDITOR )) {
  710. DebugPrint(( L"Could not set coverpage editor registry value" ));
  711. }
  712. RegCloseKey( hKey );
  713. }
  714. CreateFileAssociation(
  715. COVERPAGE_EXTENSION,
  716. GetString(IDS_COVERPAGE),
  717. GetString(IDS_COVERPAGEDESC),
  718. COVERPAGE_OPEN_COMMAND,
  719. NULL,
  720. NULL,
  721. NULL,
  722. 0
  723. );
  724. return TRUE;
  725. }
  726. BOOL
  727. SetSoundRegistryData()
  728. {
  729. HKEY hKey;
  730. LPWSTR SoundName;
  731. //
  732. // incoming fax
  733. //
  734. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL_IN, TRUE, KEY_ALL_ACCESS );
  735. if (!hKey) {
  736. DebugPrint(( L"Could not open event label registry key" ));
  737. return FALSE;
  738. }
  739. if (!SetRegistryString( hKey, NULL, GetString(IDS_INCOMING ))) {
  740. DebugPrint(( L"Could not set event label registry value" ));
  741. }
  742. RegCloseKey( hKey );
  743. //
  744. // outgoing fax
  745. //
  746. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL_OUT, TRUE, KEY_ALL_ACCESS );
  747. if (!hKey) {
  748. DebugPrint(( L"Could not open event label registry key" ));
  749. return FALSE;
  750. }
  751. if (!SetRegistryString( hKey, NULL, GetString(IDS_OUTGOING ))) {
  752. DebugPrint(( L"Could not set event label registry value" ));
  753. }
  754. RegCloseKey( hKey );
  755. //
  756. // default incoming event sound
  757. //
  758. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_DEFAULT_IN, TRUE, KEY_ALL_ACCESS );
  759. if (!hKey) {
  760. DebugPrint(( L"Could not open default sound registry key" ));
  761. return FALSE;
  762. }
  763. SoundName = ExpandEnvironmentString( L"%systemroot%\\Media\\ringin.wav" );
  764. if (!SetRegistryString( hKey, NULL, SoundName ? SoundName : L"ringin.wav" )) {
  765. DebugPrint(( L"Could not set default sound registry value" ));
  766. }
  767. RegCloseKey( hKey );
  768. //
  769. // current incoming event sound
  770. //
  771. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_CURRENT_IN, TRUE, KEY_ALL_ACCESS );
  772. if (!hKey) {
  773. DebugPrint(( L"Could not open current sound registry key" ));
  774. return FALSE;
  775. }
  776. if (!SetRegistryString( hKey, NULL, SoundName ? SoundName : L"ringin.wav" )) {
  777. DebugPrint(( L"Could not set current sound registry value" ));
  778. }
  779. if (SoundName) {
  780. MemFree( SoundName );
  781. }
  782. RegCloseKey( hKey );
  783. //
  784. // default outgoing event sound
  785. //
  786. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_DEFAULT_OUT, TRUE, KEY_ALL_ACCESS );
  787. if (!hKey) {
  788. DebugPrint(( L"Could not open default sound registry key" ));
  789. return FALSE;
  790. }
  791. SoundName = ExpandEnvironmentString( L"%systemroot%\\Media\\ringout.wav" );
  792. if (!SetRegistryString( hKey, NULL, SoundName ? SoundName : L"ringout.wav" )) {
  793. DebugPrint(( L"Could not set default sound registry value" ));
  794. }
  795. RegCloseKey( hKey );
  796. //
  797. // current outgoing event sound
  798. //
  799. hKey = OpenRegistryKey( HKEY_CURRENT_USER, REGKEY_SCHEMES_CURRENT_OUT, TRUE, KEY_ALL_ACCESS );
  800. if (!hKey) {
  801. DebugPrint(( L"Could not open current sound registry key" ));
  802. return FALSE;
  803. }
  804. if (!SetRegistryString( hKey, NULL, SoundName ? SoundName : L"ringin.wav" )) {
  805. DebugPrint(( L"Could not set current sound registry value" ));
  806. }
  807. if (SoundName) {
  808. MemFree( SoundName );
  809. }
  810. RegCloseKey( hKey );
  811. return TRUE;
  812. }
  813. BOOL
  814. GetInstallationInfo(
  815. LPDWORD Installed,
  816. LPDWORD InstallType,
  817. LPDWORD InstalledPlatforms
  818. )
  819. {
  820. HKEY hKey;
  821. LONG rVal;
  822. if (Installed) {
  823. *Installed = 0;
  824. }
  825. if (InstallType) {
  826. *InstallType = 0;
  827. }
  828. if (InstalledPlatforms) {
  829. *InstalledPlatforms = 0;
  830. }
  831. rVal = RegOpenKey(
  832. HKEY_LOCAL_MACHINE,
  833. REGKEY_FAX_SETUP,
  834. &hKey
  835. );
  836. if (rVal != ERROR_SUCCESS) {
  837. return FALSE;
  838. }
  839. if (Installed) {
  840. *Installed = GetRegistryDword( hKey, REGVAL_FAXINSTALLED );
  841. }
  842. if (InstallType) {
  843. *InstallType = GetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE );
  844. }
  845. if (InstalledPlatforms) {
  846. *InstalledPlatforms = GetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS );
  847. }
  848. RegCloseKey( hKey );
  849. return TRUE;
  850. }
  851. BOOL
  852. SetInstalledFlag(
  853. BOOL Installed
  854. )
  855. {
  856. HKEY hKey;
  857. HKEY hKeySetup;
  858. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  859. if (!hKey) {
  860. DebugPrint(( L"Could not open setup registry key" ));
  861. return FALSE;
  862. }
  863. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED, Installed )) {
  864. DebugPrint(( L"Could not set installed registry value" ));
  865. }
  866. hKeySetup = OpenRegistryKey( hKey, REGKEY_FAX_SETUP_ORIG, TRUE, KEY_ALL_ACCESS );
  867. if (!hKeySetup) {
  868. DebugPrint(( L"Could not open fax setup registry key" ));
  869. return FALSE;
  870. }
  871. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_PRINTER, WizData.RoutePrinterName )) {
  872. DebugPrint(( L"Could not set printer name registry value" ));
  873. }
  874. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_DIR, WizData.RouteDir )) {
  875. DebugPrint(( L"Could not set routing dir registry value" ));
  876. }
  877. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_PROFILE, WizData.RouteProfile )) {
  878. DebugPrint(( L"Could not set routing profile name registry value" ));
  879. }
  880. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_CSID, WizData.Csid )) {
  881. DebugPrint(( L"Could not set routing csid registry value" ));
  882. }
  883. if (!SetRegistryString( hKeySetup, REGVAL_ROUTING_TSID, WizData.Tsid )) {
  884. DebugPrint(( L"Could not set routing tsid registry value" ));
  885. }
  886. if (!SetRegistryDword( hKeySetup, REGVAL_ROUTING_MASK, WizData.RoutingMask )) {
  887. DebugPrint(( L"Could not set routing mask registry value" ));
  888. }
  889. if (!SetRegistryDword( hKeySetup, REGVAL_RINGS, WizData.Rings )) {
  890. DebugPrint(( L"Could not set rings registry value" ));
  891. }
  892. RegCloseKey( hKeySetup );
  893. RegCloseKey( hKey );
  894. return TRUE;
  895. }
  896. BOOL
  897. SetInstallType(
  898. DWORD InstallType
  899. )
  900. {
  901. HKEY hKey;
  902. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  903. if (!hKey) {
  904. DebugPrint(( L"Could not open setup registry key" ));
  905. return FALSE;
  906. }
  907. InstallType |= GetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE );
  908. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALL_TYPE, InstallType )) {
  909. DebugPrint(( L"Could not set install type registry value" ));
  910. }
  911. RegCloseKey( hKey );
  912. return TRUE;
  913. }
  914. BOOL
  915. SetInstalledPlatforms(
  916. DWORD PlatformsMask
  917. )
  918. {
  919. HKEY hKey;
  920. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_SETUP, TRUE, KEY_ALL_ACCESS );
  921. if (!hKey) {
  922. DebugPrint(( L"Could not open setup registry key" ));
  923. return FALSE;
  924. }
  925. PlatformsMask |= GetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS );
  926. if (!SetRegistryDword( hKey, REGVAL_FAXINSTALLED_PLATFORMS, PlatformsMask )) {
  927. DebugPrint(( L"Could not set install type registry value" ));
  928. }
  929. RegCloseKey( hKey );
  930. return TRUE;
  931. }
  932. BOOL
  933. DeleteRegistryTree(
  934. HKEY hKey,
  935. LPWSTR SubKey
  936. )
  937. {
  938. LONG Rval;
  939. HKEY hKeyCur;
  940. WCHAR KeyName[256];
  941. DWORD KeyNameSize;
  942. FILETIME FileTime;
  943. DWORD KeyCount;
  944. Rval = RegOpenKeyEx( hKey, SubKey, 0, KEY_ALL_ACCESS, &hKeyCur );
  945. if (Rval != ERROR_SUCCESS) {
  946. return FALSE;
  947. }
  948. KeyCount = GetSubKeyCount( hKeyCur );
  949. if (KeyCount == 0) {
  950. RegCloseKey( hKeyCur );
  951. RegDeleteKey( hKey, SubKey );
  952. return TRUE;
  953. }
  954. while( TRUE ) {
  955. KeyNameSize = sizeof(KeyName);
  956. Rval = RegEnumKeyEx( hKeyCur, 0, KeyName, &KeyNameSize, 0, NULL, NULL, &FileTime );
  957. if (Rval == ERROR_NO_MORE_ITEMS) {
  958. break;
  959. } else if (Rval != ERROR_SUCCESS) {
  960. RegCloseKey( hKeyCur );
  961. return FALSE;
  962. }
  963. if (!DeleteRegistryTree( hKeyCur, KeyName )) {
  964. RegCloseKey( hKeyCur );
  965. return FALSE;
  966. }
  967. }
  968. RegCloseKey( hKeyCur );
  969. RegDeleteKey( hKey, SubKey );
  970. return TRUE;
  971. }
  972. BOOL
  973. DeleteFaxRegistryData(
  974. VOID
  975. )
  976. {
  977. LONG Rval;
  978. HKEY hKeyCur;
  979. STARTUPINFO si;
  980. PROCESS_INFORMATION pi;
  981. HANDLE hNull;
  982. WCHAR CmdLine[128];
  983. DeleteRegistryTree( HKEY_LOCAL_MACHINE, REGKEY_FAXSERVER );
  984. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_FAXSERVER );
  985. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL_IN );
  986. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_EVENT_LABEL_OUT );
  987. DeleteRegistryTree( HKEY_CURRENT_USER, REGKEY_FAXSTAT );
  988. Rval = RegOpenKeyEx(
  989. HKEY_LOCAL_MACHINE,
  990. L"Software\\Microsoft\\Exchange\\Client\\Extensions" ,
  991. 0,
  992. KEY_ALL_ACCESS,
  993. &hKeyCur
  994. );
  995. if (Rval == ERROR_SUCCESS) {
  996. RegDeleteValue( hKeyCur, EXCHANGE_CLIENT_EXT_NAMEW );
  997. RegCloseKey( hKeyCur );
  998. }
  999. //
  1000. // unload the performance counters
  1001. //
  1002. hNull = CreateFile(
  1003. L"nul",
  1004. GENERIC_READ | GENERIC_WRITE,
  1005. 0,
  1006. NULL,
  1007. OPEN_EXISTING,
  1008. 0,
  1009. NULL
  1010. );
  1011. if (hNull != INVALID_HANDLE_VALUE) {
  1012. GetStartupInfo( &si );
  1013. si.hStdInput = hNull;
  1014. si.hStdOutput = hNull;
  1015. si.hStdError = hNull;
  1016. si.dwFlags = STARTF_USESTDHANDLES;
  1017. wcscpy( CmdLine, L"unlodctr fax" );
  1018. if (CreateProcess(
  1019. NULL,
  1020. CmdLine,
  1021. NULL,
  1022. NULL,
  1023. TRUE,
  1024. DETACHED_PROCESS,
  1025. NULL,
  1026. NULL,
  1027. &si,
  1028. &pi
  1029. ))
  1030. {
  1031. WaitForSingleObject( pi.hProcess, INFINITE );
  1032. CloseHandle( pi.hThread );
  1033. CloseHandle( pi.hProcess );
  1034. }
  1035. CloseHandle( hNull );
  1036. }
  1037. return TRUE;
  1038. }
  1039. VOID
  1040. DeleteModemRegistryKey(
  1041. VOID
  1042. )
  1043. {
  1044. HKEY hKeyDev;
  1045. INT rVal;
  1046. DWORD MaxSubKeyLen;
  1047. LPWSTR KeyNameBuf;
  1048. DWORD i;
  1049. DWORD SubKeyLen;
  1050. DWORD KeyNameLen;
  1051. rVal = RegOpenKeyEx(
  1052. HKEY_LOCAL_MACHINE,
  1053. REGKEY_FAX_DEVICES,
  1054. 0,
  1055. KEY_ALL_ACCESS,
  1056. &hKeyDev
  1057. );
  1058. if (rVal != ERROR_SUCCESS) {
  1059. DebugPrint(( L"Could not open devices registry key, ec=0x%08x", rVal ));
  1060. return;
  1061. }
  1062. MaxSubKeyLen = GetMaxSubKeyLen( hKeyDev );
  1063. if (!MaxSubKeyLen) {
  1064. return;
  1065. }
  1066. KeyNameLen =
  1067. MaxSubKeyLen +
  1068. sizeof(WCHAR) +
  1069. wcslen( REGKEY_MODEM ) +
  1070. sizeof(WCHAR) +
  1071. 32;
  1072. KeyNameBuf = (LPWSTR) MemAlloc( KeyNameLen );
  1073. if (KeyNameBuf == NULL) {
  1074. DebugPrint(( L"DeleteModemRegistryKey: MemAlloc failed" ));
  1075. return;
  1076. }
  1077. rVal = ERROR_SUCCESS;
  1078. i = 0;
  1079. while (TRUE) {
  1080. SubKeyLen = MaxSubKeyLen + sizeof(WCHAR);
  1081. rVal = RegEnumKeyEx(
  1082. hKeyDev,
  1083. i++,
  1084. KeyNameBuf,
  1085. &SubKeyLen,
  1086. NULL,
  1087. NULL,
  1088. NULL,
  1089. NULL
  1090. );
  1091. if (rVal != ERROR_SUCCESS) {
  1092. break;
  1093. }
  1094. swprintf( &KeyNameBuf[SubKeyLen], L"\\%s" , REGKEY_MODEM );
  1095. DeleteRegistryTree( hKeyDev, KeyNameBuf );
  1096. };
  1097. RegCloseKey( hKeyDev );
  1098. }
  1099. BOOL
  1100. ResetFileAssociation(
  1101. LPWSTR FileExtension,
  1102. LPWSTR FileAssociationName
  1103. )
  1104. {
  1105. HKEY hKey;
  1106. hKey = OpenRegistryKey( HKEY_CLASSES_ROOT, FileExtension, TRUE, KEY_ALL_ACCESS );
  1107. if (!hKey) {
  1108. DebugPrint(( L"Could not open file extension registry key" ));
  1109. return FALSE;
  1110. }
  1111. if (!SetRegistryString( hKey, NULL, FileAssociationName )) {
  1112. DebugPrint(( L"Could not set file association name registry value" ));
  1113. }
  1114. RegCloseKey( hKey );
  1115. return TRUE;
  1116. }
  1117. BOOL SetKeySecurity(HKEY hKey) {
  1118. long rslt;
  1119. PACL Dacl;
  1120. PACCESS_ALLOWED_ACE CurrentAce;
  1121. PSID EveryoneSid, CurrentSid;
  1122. PSECURITY_DESCRIPTOR pSecurityDescriptor;
  1123. DWORD i;
  1124. SID_IDENTIFIER_AUTHORITY WorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;
  1125. if (hKey == NULL) {
  1126. DebugPrint(( TEXT("NULL hKey, can't set security\n")));
  1127. return FALSE;
  1128. }
  1129. rslt = GetSecurityInfo( hKey,
  1130. SE_REGISTRY_KEY, // type of object
  1131. DACL_SECURITY_INFORMATION,
  1132. NULL,
  1133. NULL,
  1134. &Dacl,
  1135. NULL,
  1136. &pSecurityDescriptor);
  1137. if (rslt != ERROR_SUCCESS) {
  1138. DebugPrint(( TEXT("Couldn't GetSecurityInfo, ec = %d\n"),rslt));
  1139. return FALSE;
  1140. }
  1141. if (!IsValidSecurityDescriptor(pSecurityDescriptor)) {
  1142. DebugPrint(( TEXT("Invalid SD\n")));
  1143. return FALSE;
  1144. }
  1145. if (!AllocateAndInitializeSid(&WorldSidAuthority,
  1146. 1,
  1147. SECURITY_WORLD_RID,
  1148. 0,0,0,0,0,0,0,
  1149. &EveryoneSid) ) {
  1150. DebugPrint(( TEXT("Couldn't AllocateAndInitializedSid, ec = %d\n") , GetLastError() ));
  1151. LocalFree(pSecurityDescriptor);
  1152. return FALSE;
  1153. }
  1154. if (!IsValidSid(EveryoneSid)) {
  1155. DebugPrint(( TEXT("Couldn't AllocateAndInitializedSid, ec = %d\n") , GetLastError() ));
  1156. LocalFree(pSecurityDescriptor);
  1157. return FALSE;
  1158. }
  1159. for (i=0;i<Dacl->AceCount;i++) {
  1160. if (!GetAce(Dacl,i,(LPVOID *) &CurrentAce) ) {
  1161. DebugPrint(( TEXT("Couldn't GetAce, ec = %d\n"), GetLastError() ));
  1162. break;
  1163. }
  1164. CurrentSid = (PSID) &CurrentAce->SidStart;
  1165. if (EqualSid(EveryoneSid,CurrentSid)) {
  1166. CurrentAce->Mask &= ~(KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK | DELETE);
  1167. }
  1168. }
  1169. rslt = SetSecurityInfo( hKey, // handle to the object
  1170. SE_REGISTRY_KEY, // type of object
  1171. DACL_SECURITY_INFORMATION,// type of security information to set
  1172. NULL,// pointer to the new owner SID
  1173. NULL,// pointer to the new primary group SID
  1174. Dacl,//NewDAcl // pointer to the new DACL
  1175. NULL // pointer to the new SACL
  1176. );
  1177. if (rslt != ERROR_SUCCESS) {
  1178. DebugPrint(( TEXT("Couldn't SetSecurityInfo, ec = %d\n"), rslt ));
  1179. } else {
  1180. DebugPrint(( TEXT("SetSecurityInfo succeeded, ec = %d\n"), rslt ));
  1181. }
  1182. //
  1183. // cleanup
  1184. //
  1185. FreeSid(EveryoneSid);
  1186. LocalFree(pSecurityDescriptor);
  1187. return rslt==ERROR_SUCCESS ? TRUE : FALSE;
  1188. }