Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

871 lines
24 KiB

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