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.

859 lines
23 KiB

  1. //
  2. // reg.cxx
  3. //
  4. #include "client.hxx"
  5. BOOL SetPassword(WCHAR * szCID, WCHAR * szPw);
  6. WCHAR * ServiceName = L"ActTestService";
  7. WCHAR * ServiceDisplayName = L"ActTestService";
  8. WCHAR * UserName = L"redmond\\oleuser";
  9. WCHAR * Password = L"stocksplit";
  10. long InitializeRegistryForLocal()
  11. {
  12. SYSTEM_INFO SystemInfo;
  13. long RegStatus;
  14. ulong Disposition;
  15. HKEY hInterface;
  16. HKEY hClsidKey;
  17. HKEY hActKey;
  18. HKEY hActValueKey;
  19. WCHAR Path[256];
  20. //
  21. // Get CLASSES_ROOT.
  22. //
  23. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  24. L"CLSID",
  25. 0,
  26. KEY_ALL_ACCESS,
  27. &hClsidKey );
  28. if ( RegStatus != ERROR_SUCCESS )
  29. return RegStatus;
  30. //
  31. // Local CLSID entries.
  32. //
  33. RegStatus = RegCreateKeyEx(
  34. hClsidKey,
  35. ClsidActLocalString,
  36. 0,
  37. L"REG_SZ",
  38. REG_OPTION_NON_VOLATILE,
  39. KEY_ALL_ACCESS,
  40. NULL,
  41. &hActKey,
  42. &Disposition );
  43. if ( RegStatus != ERROR_SUCCESS )
  44. return RegStatus;
  45. RegStatus = RegCreateKeyEx(
  46. hActKey,
  47. L"LocalServer32",
  48. 0,
  49. L"REG_SZ",
  50. REG_OPTION_NON_VOLATILE,
  51. KEY_ALL_ACCESS,
  52. NULL,
  53. &hActValueKey,
  54. &Disposition );
  55. if ( RegStatus != ERROR_SUCCESS )
  56. return RegStatus;
  57. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  58. return RegStatus;
  59. _wcslwr( Path );
  60. wcscpy( wcsstr( Path, L"actclt" ), L"actsrv.exe 2" );
  61. RegStatus = RegSetValueEx(
  62. hActValueKey,
  63. L"",
  64. 0,
  65. REG_SZ,
  66. (const BYTE *)Path,
  67. (wcslen(Path) + 1) * sizeof(WCHAR) );
  68. if ( RegStatus != ERROR_SUCCESS )
  69. return RegStatus;
  70. RegStatus = RegSetValueEx(
  71. hClsidKey,
  72. L"AppID",
  73. 0,
  74. REG_SZ,
  75. (const BYTE *) ClsidActLocalString,
  76. (wcslen(ClsidActLocalString)+1)*sizeof(WCHAR));
  77. if ( RegStatus != ERROR_SUCCESS )
  78. return RegStatus;
  79. RegStatus = SetAppIDSecurity( ClsidActLocalString );
  80. if ( RegStatus != ERROR_SUCCESS )
  81. return RegStatus;
  82. return ERROR_SUCCESS;
  83. }
  84. long InitializeRegistryForInproc()
  85. {
  86. SYSTEM_INFO SystemInfo;
  87. long RegStatus;
  88. ulong Disposition;
  89. HKEY hInterface;
  90. HKEY hClsidKey;
  91. HKEY hActKey;
  92. HKEY hActValueKey;
  93. WCHAR Path[256];
  94. //
  95. // Get CLASSES_ROOT.
  96. //
  97. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  98. L"CLSID",
  99. 0,
  100. KEY_ALL_ACCESS,
  101. &hClsidKey );
  102. if ( RegStatus != ERROR_SUCCESS )
  103. return RegStatus;
  104. //
  105. // Local CLSID entries.
  106. //
  107. RegStatus = RegCreateKeyEx(
  108. hClsidKey,
  109. ClsidActInprocString,
  110. 0,
  111. L"REG_SZ",
  112. REG_OPTION_NON_VOLATILE,
  113. KEY_ALL_ACCESS,
  114. NULL,
  115. &hActKey,
  116. &Disposition );
  117. if ( RegStatus != ERROR_SUCCESS )
  118. return RegStatus;
  119. // if ( Disposition == REG_OPENED_EXISTING_KEY )
  120. // return TRUE;
  121. RegStatus = RegCreateKeyEx(
  122. hActKey,
  123. L"InprocServer32",
  124. 0,
  125. L"REG_SZ",
  126. REG_OPTION_NON_VOLATILE,
  127. KEY_ALL_ACCESS,
  128. NULL,
  129. &hActValueKey,
  130. &Disposition );
  131. if ( RegStatus != ERROR_SUCCESS )
  132. return RegStatus;
  133. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  134. return RegStatus;
  135. _wcslwr( Path );
  136. wcscpy( wcsstr( Path, L"actclt" ), L"actsrvd.dll" );
  137. RegStatus = RegSetValueEx(
  138. hActValueKey,
  139. L"",
  140. 0,
  141. REG_SZ,
  142. (const BYTE *)Path,
  143. (wcslen(Path) + 1) * sizeof(WCHAR) );
  144. if ( RegStatus != ERROR_SUCCESS )
  145. return RegStatus;
  146. RegStatus = RegSetValueEx(
  147. hActValueKey,
  148. L"ThreadingModel",
  149. 0,
  150. REG_SZ,
  151. (const BYTE *)L"Both",
  152. (wcslen(L"Both") + 1) * sizeof(WCHAR) );
  153. if ( RegStatus != ERROR_SUCCESS )
  154. return RegStatus;
  155. return ERROR_SUCCESS;
  156. }
  157. WCHAR * StringIidIGoober = L"{ffffffff-0000-0000-0000-000000000000}";
  158. long InitializeRegistryForCustom()
  159. {
  160. SYSTEM_INFO SystemInfo;
  161. long RegStatus;
  162. ulong Disposition;
  163. HKEY hInterface;
  164. HKEY hClsidKey;
  165. HKEY hActKey;
  166. HKEY hActValueKey;
  167. WCHAR Path[256];
  168. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  169. L"Interface",
  170. 0,
  171. KEY_ALL_ACCESS,
  172. &hInterface );
  173. if ( RegStatus != ERROR_SUCCESS )
  174. return RegStatus;
  175. RegStatus = RegCreateKeyEx(
  176. hInterface,
  177. StringIidIGoober,
  178. 0,
  179. L"REG_SZ",
  180. REG_OPTION_NON_VOLATILE,
  181. KEY_ALL_ACCESS,
  182. NULL,
  183. &hInterface,
  184. &Disposition );
  185. if ( RegStatus != ERROR_SUCCESS )
  186. return RegStatus;
  187. RegStatus = RegSetValueEx(
  188. hInterface,
  189. L"",
  190. 0,
  191. REG_SZ,
  192. (const BYTE *)L"IGoober",
  193. (wcslen(L"IGoober") + 1) * sizeof(WCHAR) );
  194. if ( RegStatus != ERROR_SUCCESS )
  195. return RegStatus;
  196. RegStatus = RegCreateKeyEx(
  197. hInterface,
  198. L"ProxyStubClsid32",
  199. 0,
  200. L"REG_SZ",
  201. REG_OPTION_NON_VOLATILE,
  202. KEY_ALL_ACCESS,
  203. NULL,
  204. &hInterface,
  205. &Disposition );
  206. if ( RegStatus != ERROR_SUCCESS )
  207. return RegStatus;
  208. RegStatus = RegSetValueEx(
  209. hInterface,
  210. L"",
  211. 0,
  212. REG_SZ,
  213. (const BYTE *)ClsidGoober32String,
  214. (wcslen(ClsidGoober32String) + 1) * sizeof(WCHAR) );
  215. if ( RegStatus != ERROR_SUCCESS )
  216. return RegStatus;
  217. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  218. L"CLSID",
  219. 0,
  220. KEY_ALL_ACCESS,
  221. &hClsidKey );
  222. if ( RegStatus != ERROR_SUCCESS )
  223. return RegStatus;
  224. RegStatus = RegCreateKeyEx(
  225. hClsidKey,
  226. ClsidGoober32String,
  227. 0,
  228. L"REG_SZ",
  229. REG_OPTION_NON_VOLATILE,
  230. KEY_ALL_ACCESS,
  231. NULL,
  232. &hActKey,
  233. &Disposition );
  234. if ( RegStatus != ERROR_SUCCESS )
  235. return RegStatus;
  236. // if ( Disposition == REG_OPENED_EXISTING_KEY )
  237. // return TRUE;
  238. RegStatus = RegCreateKeyEx(
  239. hActKey,
  240. L"InProcServer32",
  241. 0,
  242. L"REG_SZ",
  243. REG_OPTION_NON_VOLATILE,
  244. KEY_ALL_ACCESS,
  245. NULL,
  246. &hActValueKey,
  247. &Disposition );
  248. if ( RegStatus != ERROR_SUCCESS )
  249. return RegStatus;
  250. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  251. return RegStatus;
  252. _wcslwr( Path );
  253. wcscpy( wcsstr( Path, L"actclt" ), L"goober.dll" );
  254. RegStatus = RegSetValueEx(
  255. hActValueKey,
  256. L"",
  257. 0,
  258. REG_SZ,
  259. (const BYTE *)Path,
  260. (wcslen(Path) + 1) * sizeof(WCHAR) );
  261. if ( RegStatus != ERROR_SUCCESS )
  262. return RegStatus;
  263. return ERROR_SUCCESS;
  264. }
  265. long InitializeRegistryForRemote()
  266. {
  267. long RegStatus;
  268. ulong Disposition;
  269. HKEY hClsidKey;
  270. HKEY hAppIDKey;
  271. HKEY hThisClsidKey;
  272. HKEY hActKey;
  273. HKEY hActValueKey;
  274. WCHAR Path[256];
  275. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  276. L"CLSID",
  277. 0,
  278. KEY_ALL_ACCESS,
  279. &hClsidKey );
  280. if ( RegStatus != ERROR_SUCCESS )
  281. return RegStatus;
  282. //
  283. // CLSID_ActRemote
  284. //
  285. RegStatus = RegCreateKeyEx(
  286. hClsidKey,
  287. ClsidActRemoteString,
  288. 0,
  289. L"REG_SZ",
  290. REG_OPTION_NON_VOLATILE,
  291. KEY_ALL_ACCESS,
  292. NULL,
  293. &hThisClsidKey,
  294. &Disposition );
  295. if ( RegStatus != ERROR_SUCCESS )
  296. return RegStatus;
  297. RegStatus = RegSetValueEx(
  298. hThisClsidKey,
  299. L"AppID",
  300. 0,
  301. REG_SZ,
  302. (const BYTE *) ClsidActRemoteString,
  303. (wcslen(ClsidActRemoteString)+1)*sizeof(WCHAR));
  304. if ( RegStatus != ERROR_SUCCESS )
  305. return RegStatus;
  306. RegStatus = SetAppIDSecurity( ClsidActRemoteString );
  307. if ( RegStatus != ERROR_SUCCESS )
  308. return RegStatus;
  309. RegStatus = RegCreateKeyEx(
  310. HKEY_CLASSES_ROOT,
  311. L"AppID",
  312. 0,
  313. L"REG_SZ",
  314. REG_OPTION_NON_VOLATILE,
  315. KEY_ALL_ACCESS,
  316. NULL,
  317. &hAppIDKey,
  318. &Disposition );
  319. if ( RegStatus != ERROR_SUCCESS )
  320. return RegStatus;
  321. RegStatus = RegCreateKeyEx(
  322. hAppIDKey,
  323. ClsidActRemoteString,
  324. 0,
  325. L"REG_SZ",
  326. REG_OPTION_NON_VOLATILE,
  327. KEY_ALL_ACCESS,
  328. NULL,
  329. &hActKey,
  330. &Disposition );
  331. if ( RegStatus != ERROR_SUCCESS )
  332. return RegStatus;
  333. RegStatus = RegSetValueEx(
  334. hActKey,
  335. L"RemoteServerName",
  336. 0,
  337. REG_SZ,
  338. (const BYTE *)ServerName,
  339. (wcslen(ServerName) + 1) * sizeof(WCHAR) );
  340. if ( RegStatus != ERROR_SUCCESS )
  341. return RegStatus;
  342. //
  343. // CLSID_ActAtStorage
  344. //
  345. RegStatus = RegCreateKeyEx(
  346. hClsidKey,
  347. ClsidActAtStorageString,
  348. 0,
  349. L"REG_SZ",
  350. REG_OPTION_NON_VOLATILE,
  351. KEY_ALL_ACCESS,
  352. NULL,
  353. &hThisClsidKey,
  354. &Disposition );
  355. if ( RegStatus != ERROR_SUCCESS )
  356. return RegStatus;
  357. RegStatus = RegSetValueEx(
  358. hThisClsidKey,
  359. L"AppID",
  360. 0,
  361. REG_SZ,
  362. (const BYTE *) ClsidActAtStorageString,
  363. (wcslen(ClsidActAtStorageString)+1)*sizeof(WCHAR));
  364. if ( RegStatus != ERROR_SUCCESS )
  365. return RegStatus;
  366. RegStatus = SetAppIDSecurity( ClsidActAtStorageString );
  367. if ( RegStatus != ERROR_SUCCESS )
  368. return RegStatus;
  369. RegStatus = RegCreateKeyEx(
  370. hAppIDKey,
  371. ClsidActAtStorageString,
  372. 0,
  373. L"REG_SZ",
  374. REG_OPTION_NON_VOLATILE,
  375. KEY_ALL_ACCESS,
  376. NULL,
  377. &hActKey,
  378. &Disposition );
  379. if ( RegStatus != ERROR_SUCCESS )
  380. return RegStatus;
  381. RegStatus = RegSetValueEx(
  382. hActKey,
  383. L"ActivateAtStorage",
  384. 0,
  385. REG_SZ,
  386. (const BYTE *)L"Y",
  387. (wcslen(L"Y") + 1) * sizeof(WCHAR) );
  388. if ( RegStatus != ERROR_SUCCESS )
  389. return RegStatus;
  390. //
  391. // CLSID_ActRunAsLoggedOnUser
  392. //
  393. RegStatus = RegCreateKeyEx(
  394. hClsidKey,
  395. ClsidActRunAsLoggedOnString,
  396. 0,
  397. L"REG_SZ",
  398. REG_OPTION_NON_VOLATILE,
  399. KEY_ALL_ACCESS,
  400. NULL,
  401. &hThisClsidKey,
  402. &Disposition );
  403. if ( RegStatus != ERROR_SUCCESS )
  404. return RegStatus;
  405. RegStatus = SetAppIDSecurity( ClsidActRunAsLoggedOnString );
  406. if ( RegStatus != ERROR_SUCCESS )
  407. return RegStatus;
  408. RegStatus = RegSetValueEx(
  409. hThisClsidKey,
  410. L"AppID",
  411. 0,
  412. REG_SZ,
  413. (const BYTE *) ClsidActRunAsLoggedOnString,
  414. (wcslen(ClsidActRunAsLoggedOnString)+1)*sizeof(WCHAR));
  415. if ( RegStatus != ERROR_SUCCESS )
  416. return RegStatus;
  417. RegStatus = RegCreateKeyEx(
  418. hAppIDKey,
  419. ClsidActRunAsLoggedOnString,
  420. 0,
  421. L"REG_SZ",
  422. REG_OPTION_NON_VOLATILE,
  423. KEY_ALL_ACCESS,
  424. NULL,
  425. &hActKey,
  426. &Disposition );
  427. if ( RegStatus != ERROR_SUCCESS )
  428. return RegStatus;
  429. RegStatus = RegSetValueEx(
  430. hActKey,
  431. L"RemoteServerName",
  432. 0,
  433. REG_SZ,
  434. (const BYTE *)ServerName,
  435. (wcslen(ServerName) + 1) * sizeof(WCHAR) );
  436. if ( RegStatus != ERROR_SUCCESS )
  437. return RegStatus;
  438. RegStatus = RegCreateKeyEx(
  439. hThisClsidKey,
  440. L"LocalServer32",
  441. 0,
  442. L"REG_SZ",
  443. REG_OPTION_NON_VOLATILE,
  444. KEY_ALL_ACCESS,
  445. NULL,
  446. &hActValueKey,
  447. &Disposition );
  448. if ( RegStatus != ERROR_SUCCESS )
  449. return RegStatus;
  450. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  451. return RegStatus;
  452. _wcslwr( Path );
  453. wcscpy( wcsstr( Path, L"actclt" ), L"actsrv.exe 7" );
  454. RegStatus = RegSetValueEx(
  455. hActValueKey,
  456. L"",
  457. 0,
  458. REG_SZ,
  459. (const BYTE *)Path,
  460. (wcslen(Path) + 1) * sizeof(WCHAR) );
  461. RegStatus = RegSetValueEx(
  462. hActKey,
  463. L"RunAs",
  464. 0,
  465. REG_SZ,
  466. (const BYTE *)L"Interactive User",
  467. (wcslen(L"Interactive User") + 1) * sizeof(WCHAR) );
  468. if ( RegStatus != ERROR_SUCCESS )
  469. return RegStatus;
  470. //
  471. // RunAs CLSID entries.
  472. //
  473. RegStatus = RegCreateKeyEx(
  474. hClsidKey,
  475. ClsidActPreConfigString,
  476. 0,
  477. L"REG_SZ",
  478. REG_OPTION_NON_VOLATILE,
  479. KEY_ALL_ACCESS,
  480. NULL,
  481. &hThisClsidKey,
  482. &Disposition );
  483. if ( RegStatus != ERROR_SUCCESS )
  484. return RegStatus;
  485. RegStatus = RegSetValueEx(
  486. hThisClsidKey,
  487. L"AppID",
  488. 0,
  489. REG_SZ,
  490. (const BYTE *) ClsidActPreConfigString,
  491. (wcslen(ClsidActPreConfigString)+1)*sizeof(WCHAR));
  492. if ( RegStatus != ERROR_SUCCESS )
  493. return RegStatus;
  494. RegStatus = SetAppIDSecurity( ClsidActPreConfigString );
  495. if ( RegStatus != ERROR_SUCCESS )
  496. return RegStatus;
  497. RegStatus = RegCreateKeyEx(
  498. hAppIDKey,
  499. ClsidActPreConfigString,
  500. 0,
  501. L"REG_SZ",
  502. REG_OPTION_NON_VOLATILE,
  503. KEY_ALL_ACCESS,
  504. NULL,
  505. &hActKey,
  506. &Disposition );
  507. if ( RegStatus != ERROR_SUCCESS )
  508. return RegStatus;
  509. RegStatus = RegSetValueEx(
  510. hActKey,
  511. L"RemoteServerName",
  512. 0,
  513. REG_SZ,
  514. (const BYTE *)ServerName,
  515. (wcslen(ServerName) + 1) * sizeof(WCHAR) );
  516. if ( RegStatus != ERROR_SUCCESS )
  517. return RegStatus;
  518. RegStatus = RegCreateKeyEx(
  519. hThisClsidKey,
  520. L"LocalServer32",
  521. 0,
  522. L"REG_SZ",
  523. REG_OPTION_NON_VOLATILE,
  524. KEY_ALL_ACCESS,
  525. NULL,
  526. &hActValueKey,
  527. &Disposition );
  528. if ( RegStatus != ERROR_SUCCESS )
  529. return RegStatus;
  530. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  531. return RegStatus;
  532. _wcslwr( Path );
  533. wcscpy( wcsstr( Path, L"actclt" ), L"actsrv.exe 6" );
  534. RegStatus = RegSetValueEx(
  535. hActValueKey,
  536. L"",
  537. 0,
  538. REG_SZ,
  539. (const BYTE *)Path,
  540. (wcslen(Path) + 1) * sizeof(WCHAR) );
  541. RegStatus = RegSetValueEx(
  542. hActKey,
  543. L"RunAs",
  544. 0,
  545. REG_SZ,
  546. (const BYTE *)UserName,
  547. (wcslen(UserName) + 1) * sizeof(WCHAR) );
  548. if ( RegStatus != ERROR_SUCCESS )
  549. return RegStatus;
  550. if (!SetPassword(ClsidActPreConfigString, Password))
  551. return(FALSE);
  552. return ERROR_SUCCESS;
  553. }
  554. long InitializeRegistryForService()
  555. {
  556. long RegStatus;
  557. ulong Disposition;
  558. HKEY hClsidKey;
  559. HKEY hAppIDKey;
  560. HKEY hThisClsidKey;
  561. HKEY hActKey;
  562. HKEY hActValueKey;
  563. HKEY hServices;
  564. WCHAR Path[256];
  565. //
  566. // Get CLASSES_ROOT.
  567. //
  568. RegStatus = RegOpenKeyEx( HKEY_CLASSES_ROOT,
  569. L"CLSID",
  570. 0,
  571. KEY_ALL_ACCESS,
  572. &hClsidKey );
  573. if ( RegStatus != ERROR_SUCCESS )
  574. return RegStatus;
  575. RegStatus = RegCreateKeyEx(
  576. HKEY_CLASSES_ROOT,
  577. L"AppID",
  578. 0,
  579. L"REG_SZ",
  580. REG_OPTION_NON_VOLATILE,
  581. KEY_ALL_ACCESS,
  582. NULL,
  583. &hAppIDKey,
  584. &Disposition );
  585. if ( RegStatus != ERROR_SUCCESS )
  586. return RegStatus;
  587. //
  588. // Local CLSID entries.
  589. //
  590. RegStatus = RegCreateKeyEx(
  591. hClsidKey,
  592. ClsidActServiceString,
  593. 0,
  594. L"REG_SZ",
  595. REG_OPTION_NON_VOLATILE,
  596. KEY_ALL_ACCESS,
  597. NULL,
  598. &hThisClsidKey,
  599. &Disposition );
  600. if ( RegStatus != ERROR_SUCCESS )
  601. return RegStatus;
  602. RegStatus = SetAppIDSecurity( ClsidActServiceString );
  603. if ( RegStatus != ERROR_SUCCESS )
  604. return RegStatus;
  605. RegStatus = RegSetValueEx(
  606. hThisClsidKey,
  607. L"AppID",
  608. 0,
  609. REG_SZ,
  610. (const BYTE *) ClsidActServiceString,
  611. (wcslen(ClsidActServiceString)+1)*sizeof(WCHAR));
  612. if ( RegStatus != ERROR_SUCCESS )
  613. return RegStatus;
  614. // if ( Disposition == REG_OPENED_EXISTING_KEY )
  615. // return TRUE;
  616. RegStatus = RegCreateKeyEx(
  617. hAppIDKey,
  618. ClsidActServiceString,
  619. 0,
  620. L"REG_SZ",
  621. REG_OPTION_NON_VOLATILE,
  622. KEY_ALL_ACCESS,
  623. NULL,
  624. &hActKey,
  625. &Disposition );
  626. if ( RegStatus != ERROR_SUCCESS )
  627. return RegStatus;
  628. if ( ! GetModuleFileName( 0, Path, sizeof(Path) ) )
  629. return RegStatus;
  630. _wcslwr( Path );
  631. wcscpy( wcsstr( Path, L"actclt" ), L"actsrv.exe 8" );
  632. RegStatus = RegSetValueEx(
  633. hActKey,
  634. L"LocalService",
  635. 0,
  636. REG_SZ,
  637. (const BYTE *)ServiceName,
  638. (wcslen(ServiceName) + 1) * sizeof(WCHAR) );
  639. if ( RegStatus != ERROR_SUCCESS )
  640. return RegStatus;
  641. RegStatus = RegSetValueEx(
  642. hActKey,
  643. L"ActivateAtStorage",
  644. 0,
  645. REG_SZ,
  646. (const BYTE *)L"Y",
  647. (wcslen(L"Y") + 1) * sizeof(WCHAR) );
  648. if ( RegStatus != ERROR_SUCCESS )
  649. return RegStatus;
  650. RegStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  651. L"SYSTEM\\CurrentControlSet\\Services",
  652. 0,
  653. KEY_READ,
  654. &hServices );
  655. if ( RegStatus != ERROR_SUCCESS )
  656. return RegStatus;
  657. return InstallService(Path);
  658. }
  659. DWORD InstallService( WCHAR * Path )
  660. {
  661. SC_HANDLE hManager;
  662. SC_HANDLE hService;
  663. hManager = OpenSCManager( NULL,
  664. NULL,
  665. SC_MANAGER_ALL_ACCESS );
  666. if ( ! hManager )
  667. {
  668. printf( "OpenSCManager returned %d\n", GetLastError() );
  669. return GetLastError();
  670. }
  671. hService = OpenService( hManager,
  672. ServiceName,
  673. SERVICE_ALL_ACCESS );
  674. if ( ! hService )
  675. {
  676. hService = CreateService(
  677. hManager,
  678. ServiceName,
  679. ServiceDisplayName,
  680. SERVICE_ALL_ACCESS,
  681. SERVICE_WIN32_OWN_PROCESS,
  682. SERVICE_DEMAND_START,
  683. SERVICE_ERROR_NORMAL,
  684. Path,
  685. NULL,
  686. NULL,
  687. NULL,
  688. NULL,
  689. NULL);
  690. }
  691. if ( ! hService )
  692. {
  693. printf( "CreateService returned %d\n", GetLastError() );
  694. CloseServiceHandle(hManager);
  695. return GetLastError();
  696. }
  697. CloseServiceHandle(hService);
  698. CloseServiceHandle(hManager);
  699. return ERROR_SUCCESS;
  700. }