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.

798 lines
24 KiB

  1. /*******************************************************************************
  2. *
  3. * Copyright 1999 American Power Conversion, All Rights Reserved
  4. *
  5. * TITLE: UPSCOMMON.C
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: SteveT
  10. *
  11. * DATE: 07 June, 1999
  12. *
  13. * DESCRIPTION: This file contains functions that are used by various different module,
  14. * or are generic enough to be used by varoius different modules even if
  15. * they are only being used in one place at present.
  16. ********************************************************************************/
  17. #include "upstab.h"
  18. #include "prsht.h"
  19. #pragma hdrstop
  20. // static data
  21. ///////////////////////////////////////////////////////////////////////////////
  22. static HWND g_hUPSPage = 0; //Used in
  23. //InitializeApplyButton and
  24. //EnableApplyButton
  25. static DWORD g_CurrentActiveDataState = 0; //Used in
  26. //AddActiveDataState
  27. //GetActiveDataState and
  28. //SetActiveDataState
  29. extern HINSTANCE g_hInstance; //Global instance handle of this DLL
  30. // functions
  31. ///////////////////////////////////////////////////////////////////////////////
  32. DWORD GetServiceStatus_Control (LPCTSTR aServiceName, LPDWORD lpStatus);
  33. DWORD GetServiceStatus_Query (LPCTSTR aServiceName, LPDWORD lpStatus);
  34. DWORD GetServiceStatus_Enum (LPCTSTR aServiceName, LPDWORD lpStatus);
  35. DWORD ManageService (LPCTSTR aServiceName,
  36. DWORD aDesiredSCAccess,
  37. DWORD aDesiredServiceAccess,
  38. DWORD aAction,
  39. BOOL bWait,
  40. DWORD aWaitStatus,
  41. LPDWORD lpStatus);
  42. BOOL WaitForServiceStatus (SC_HANDLE aHandle, DWORD aStatus);
  43. DWORD LoadUPSString (DWORD aMsgID,
  44. LPTSTR aMessageBuffer,
  45. DWORD * aBufferSizePtr);
  46. ///////////////////////////////////////////////////////////////////////////////
  47. ///////////////////////////////////////////////////////////////////////////////
  48. ///////////////////////////////////////////////////////////////////////////////
  49. //////////////////////////////////////////////////////////////////////////_/_//
  50. //////////////////////////////////////////////////////////////////////////_/_//
  51. // HMODULE GetUPSModuleHandle (void);
  52. //
  53. // Description: This function gets the HMODULE of the module that created
  54. // the UPS tab dialog.
  55. //
  56. // Additional Information:
  57. //
  58. // Parameters: None
  59. //
  60. // Return Value: Returns the HMODULE of the module that created the dialog.
  61. //
  62. HMODULE GetUPSModuleHandle (void) {
  63. static HMODULE hModule = NULL;
  64. if (hModule == NULL) {
  65. #ifdef _APC_
  66. hModule = GetModuleHandle(UPS_EXE_FILE);
  67. #else
  68. hModule = g_hInstance;
  69. #endif
  70. }
  71. return(hModule);
  72. }
  73. //////////////////////////////////////////////////////////////////////////_/_//
  74. //////////////////////////////////////////////////////////////////////////_/_//
  75. // void InitializeApplyButton (HWND aDlgHWND);
  76. //
  77. // Description: This function sets the data needed to allow the
  78. // EnableApplyButton to
  79. //
  80. // Additional Information:
  81. //
  82. // Parameters:
  83. //
  84. // HWND aDlgHWND :-
  85. //
  86. // Return Value: None
  87. //
  88. void InitializeApplyButton (HWND aDlgHWND) {
  89. _ASSERT(g_hUPSPage == 0);
  90. _ASSERT(aDlgHWND != 0);
  91. g_hUPSPage = aDlgHWND;
  92. }
  93. //////////////////////////////////////////////////////////////////////////_/_//
  94. //////////////////////////////////////////////////////////////////////////_/_//
  95. // void EnableApplyButton (void);
  96. //
  97. // Description: This function enables the "Apply" button on the main UPS page
  98. //
  99. // Additional Information:
  100. //
  101. // Parameters: None
  102. //
  103. // Return Value: None
  104. //
  105. void EnableApplyButton (void) {
  106. HWND hParent = 0;
  107. _ASSERT(g_hUPSPage != 0); //Should call InitializeApplyButton
  108. //to initialize.
  109. hParent = GetParent(g_hUPSPage);
  110. PropSheet_Changed(hParent, g_hUPSPage);
  111. }
  112. //////////////////////////////////////////////////////////////////////////_/_//
  113. //////////////////////////////////////////////////////////////////////////_/_//
  114. // BOOL RestartService (LPCTSTR aServiceName, BOOL bWait);
  115. //
  116. // Description: This function restarts the specified service
  117. //
  118. // Additional Information:
  119. //
  120. // Parameters:
  121. //
  122. // LPCTSTR aServiceName :- The name of the service to restart
  123. //
  124. // BOOL bWait :- A BOOL that specifies if the process should wait for the
  125. // the service to fully restart. If TRUE then this process
  126. // returns when the service has fully restarted. If FALSE
  127. // then this process tells the service to start but does
  128. // not wait around for it to be fully started before returning.
  129. //
  130. // Return Value: If the given service restarts successfully then this function
  131. // returns TRUE, otherwise it returns FALSE.
  132. //
  133. BOOL RestartService (LPCTSTR aServiceName, BOOL bWait) {
  134. StopService(aServiceName);
  135. return(StartOffService(aServiceName, bWait));
  136. }
  137. //////////////////////////////////////////////////////////////////////////_/_//
  138. //////////////////////////////////////////////////////////////////////////_/_//
  139. // BOOL StartOffService (LPCTSTR aServiceName, BOOL bWaitForService);
  140. //
  141. // Description: This function starts the specified service
  142. //
  143. // Additional Information:
  144. //
  145. // Parameters:
  146. //
  147. // LPCTSTR aServiceName :- The name of the service to start
  148. //
  149. // BOOL bWaitForService :- A BOOL that specifies if the process should wait
  150. // for the the service to fully start. If TRUE then
  151. // this process returns when the service has fully
  152. // started. If FALSE then this process tells the
  153. // service to start but does not wait around for it
  154. // to be fully started before returning.
  155. //
  156. // Return Value: If the given service starts successfully then this function
  157. // returns TRUE, otherwise it returns FALSE.
  158. //
  159. BOOL StartOffService (LPCTSTR aServiceName, BOOL bWaitForService) {
  160. BOOL bStartedOK = FALSE;
  161. SC_HANDLE hManager = NULL;
  162. if ((hManager = OpenSCManager(NULL, NULL, GENERIC_READ)) != NULL) {
  163. SC_HANDLE service_handle = NULL;
  164. if ((service_handle = OpenService(hManager,
  165. aServiceName,
  166. SERVICE_START | SERVICE_INTERROGATE | SERVICE_QUERY_STATUS)) != NULL) {
  167. SERVICE_STATUS service_status;
  168. SetLastError(0);
  169. ZeroMemory(&service_status, sizeof(service_status));
  170. if ((bStartedOK = StartService(service_handle,
  171. 0,
  172. NULL)) == TRUE) {
  173. SetLastError(0);
  174. if (bWaitForService == TRUE) {
  175. bStartedOK = WaitForServiceStatus(service_handle, SERVICE_RUNNING);
  176. }
  177. }
  178. else {
  179. _ASSERT(FALSE);
  180. }
  181. if (CloseServiceHandle(service_handle) == FALSE) {
  182. _ASSERT(FALSE);
  183. //error closing service configuration manager
  184. }
  185. }
  186. if (CloseServiceHandle(hManager) == FALSE) {
  187. //error closing service configuration manager
  188. _ASSERT(FALSE);
  189. }
  190. }
  191. return(bStartedOK);
  192. }
  193. //////////////////////////////////////////////////////////////////////////_/_//
  194. //////////////////////////////////////////////////////////////////////////_/_//
  195. // BOOL WaitForServiceStatus (SC_HANDLE aHandle, DWORD aStatus);
  196. //
  197. // Description: This function waits for the service identified by the given
  198. // service handle to enter the given state.
  199. //
  200. // Additional Information:
  201. //
  202. // Parameters:
  203. //
  204. // SC_HANDLE aHandle :- A handle to an open service.
  205. //
  206. // DWORD aStatus :- The status to wait for. The allows value for this
  207. // parameter are defined by the dwCurrentState member of the
  208. // structure.
  209. //
  210. // Return Value:
  211. //
  212. BOOL WaitForServiceStatus (SC_HANDLE aHandle, DWORD aStatus) {
  213. SERVICE_STATUS service_status;
  214. DWORD dwOldCheck = 0;
  215. BOOL bStatusSet = FALSE;
  216. ZeroMemory(&service_status, sizeof(service_status));
  217. bStatusSet = QueryServiceStatus(aHandle, &service_status);
  218. if (bStatusSet == FALSE) {
  219. return(bStatusSet);
  220. }
  221. while (service_status.dwCurrentState != aStatus) {
  222. dwOldCheck = service_status.dwCheckPoint;
  223. Sleep(service_status.dwWaitHint);
  224. if ((bStatusSet = QueryServiceStatus(aHandle, &service_status)) == FALSE) {
  225. break;
  226. }
  227. if (dwOldCheck >= service_status.dwCheckPoint) {
  228. break;
  229. }
  230. }//end while
  231. if (service_status.dwCurrentState == aStatus) {
  232. bStatusSet = TRUE;
  233. }
  234. else {
  235. TCHAR errMessageBuffer[MAX_PATH] = TEXT("");
  236. DWORD errMessageBufferSize = MAX_PATH;
  237. bStatusSet = FALSE;
  238. //Must load the error message from "netmsg.dll"
  239. if ((LoadUPSString(service_status.dwWin32ExitCode,
  240. errMessageBuffer,
  241. &errMessageBufferSize) == ERROR_SUCCESS) &&
  242. (*errMessageBuffer != TEXT('\0'))) {
  243. MessageBox(NULL, errMessageBuffer, NULL, MB_OK | MB_ICONEXCLAMATION);
  244. }
  245. }
  246. return(bStatusSet);
  247. }
  248. //////////////////////////////////////////////////////////////////////////_/_//
  249. //////////////////////////////////////////////////////////////////////////_/_//
  250. // DWORD LoadUPSString (DWORD aMsgID,
  251. // LPTSTR aMessageBuffer,
  252. // DWORD * aBufferSizePtr);
  253. //
  254. // Description: This function load the string resource identified by aMsgID
  255. // into the buffer identified by aMessageBuffer
  256. //
  257. // Additional Information:
  258. //
  259. // Parameters:
  260. //
  261. // DWORD aMsgID :- ID of string resource to load
  262. //
  263. // LPTSTR aMessageBuffer :- Pointer to a buffer where the string is to be
  264. // copied.
  265. //
  266. // DWORD * aBufferSizePtr :- The size of the buffer.
  267. //
  268. // Return Value: Returns a Win32 error code. ERROR_SUCCESS on success.
  269. //
  270. DWORD LoadUPSString (DWORD aMsgID,
  271. LPTSTR aMessageBuffer,
  272. DWORD * aBufferSizePtr) {
  273. LPTSTR lpBuf = NULL; // Will Hold text of the message (allocated by FormatMessage
  274. DWORD errStatus = ERROR_SUCCESS;
  275. DWORD numChars = 0;
  276. HMODULE hNetMsg = LoadLibrary(TEXT("netmsg.dll"));
  277. if (hNetMsg != NULL) {
  278. if (numChars = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  279. (LPCVOID) hNetMsg,
  280. aMsgID,
  281. 0,
  282. (LPTSTR) &lpBuf,
  283. *aBufferSizePtr,
  284. (va_list *)0) == 0) {
  285. *aBufferSizePtr = 0;
  286. *aMessageBuffer = TEXT('\0');
  287. }
  288. else {
  289. if (aBufferSizePtr != NULL) {
  290. if (numChars < *aBufferSizePtr) {
  291. //the given buffer is big enough to hold the string
  292. if (aMessageBuffer != NULL) {
  293. _tcscpy(aMessageBuffer, lpBuf);
  294. }
  295. }
  296. *aBufferSizePtr = numChars;
  297. }
  298. LocalFree(lpBuf);
  299. }
  300. FreeLibrary(hNetMsg);
  301. }
  302. return(errStatus);
  303. }
  304. //////////////////////////////////////////////////////////////////////////_/_//
  305. //////////////////////////////////////////////////////////////////////////_/_//
  306. // void StopService (LPCTSTR aServiceName);
  307. //
  308. // Description: This function stops the service named.
  309. //
  310. // Additional Information:
  311. //
  312. // Parameters:
  313. //
  314. // LPCTSTR aServiceName :- The name of the service
  315. //
  316. // Return Value: None
  317. //
  318. void StopService (LPCTSTR aServiceName) {
  319. DWORD dwStatus = SERVICE_STOPPED;
  320. DWORD dwError = ERROR_SUCCESS;
  321. dwError = ManageService(aServiceName,
  322. GENERIC_READ,
  323. SERVICE_STOP | SERVICE_INTERROGATE | SERVICE_QUERY_STATUS,
  324. SERVICE_CONTROL_STOP,
  325. TRUE,
  326. SERVICE_STOPPED,
  327. &dwStatus);
  328. }
  329. //////////////////////////////////////////////////////////////////////////_/_//
  330. //////////////////////////////////////////////////////////////////////////_/_//
  331. // BOOL IsServiceRunning (LPCTSTR aServiceName);
  332. //
  333. // Description: This function checks if the service named is running.
  334. //
  335. // Additional Information:
  336. //
  337. // Parameters:
  338. //
  339. // LPCTSTR aServiceName :- The name of the service
  340. //
  341. // Return Value: TRUE if the service is running, FALSE otherwise.
  342. //
  343. BOOL IsServiceRunning (LPCTSTR aServiceName)
  344. {
  345. DWORD dwStatus = SERVICE_STOPPED;
  346. // There are three methods of retrieving the service status
  347. // 1. Interrogate the service using ControlService() - most accurate
  348. // 2. Query the service using QueryServiceStatus() - most efficient
  349. // 3. Query the service using EnumServicesStatus() - most accessible
  350. if (GetServiceStatus_Control(aServiceName, &dwStatus) != ERROR_SUCCESS)
  351. {
  352. if (GetServiceStatus_Query(aServiceName, &dwStatus) != ERROR_SUCCESS)
  353. {
  354. GetServiceStatus_Enum(aServiceName, &dwStatus);
  355. }
  356. }
  357. return(SERVICE_RUNNING == dwStatus);
  358. }
  359. //////////////////////////////////////////////////////////////////////////_/_//
  360. //////////////////////////////////////////////////////////////////////////_/_//
  361. // DWORD GetServiceStatus_Control (LPCTSTR aServiceName, LPDWORD lpStatus);
  362. //
  363. // Description: This function returns the status of the service named
  364. // using the Win32 API call ControlService(). This is the
  365. // most accurate way to retrieve the service staus.
  366. //
  367. // Parameters:
  368. //
  369. // IN
  370. // LPCTSTR aServiceName :- The name of the service
  371. //
  372. // OUT
  373. // LPDWORD lpStatus :- The service status
  374. //
  375. // Return Value: Returns a Win32 error code. ERROR_SUCCESS on success.
  376. //
  377. DWORD GetServiceStatus_Control (LPCTSTR aServiceName, LPDWORD lpStatus)
  378. {
  379. DWORD dwError = ERROR_SUCCESS;
  380. *lpStatus = SERVICE_STOPPED;
  381. dwError = ManageService(aServiceName,
  382. SC_MANAGER_ENUMERATE_SERVICE,
  383. SERVICE_INTERROGATE | SERVICE_QUERY_STATUS,
  384. SERVICE_CONTROL_INTERROGATE,
  385. FALSE,
  386. 0,
  387. lpStatus);
  388. return dwError;
  389. }
  390. //////////////////////////////////////////////////////////////////////////_/_//
  391. //////////////////////////////////////////////////////////////////////////_/_//
  392. // DWORD GetServiceStatus_Query (LPCTSTR aServiceName, LPDWORD lpStatus);
  393. //
  394. // Description: This function returns the status of the service named.
  395. // using the Win32 API call QueryServiceStatus(). This is the
  396. // most efficient way to retrieve the service staus.
  397. //
  398. // Parameters:
  399. //
  400. // IN
  401. // LPCTSTR aServiceName :- The name of the service
  402. //
  403. // OUT
  404. // LPDWORD lpStatus :- The service status
  405. //
  406. // Return Value: Returns a Win32 error code. ERROR_SUCCESS on success.
  407. //
  408. DWORD GetServiceStatus_Query (LPCTSTR aServiceName, LPDWORD lpStatus)
  409. {
  410. DWORD dwError = ERROR_SUCCESS;
  411. SC_HANDLE hManager = NULL;
  412. *lpStatus = SERVICE_STOPPED;
  413. if (NULL != (hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE)))
  414. {
  415. SC_HANDLE service_handle = NULL;
  416. if (NULL != (service_handle = OpenService(hManager,
  417. aServiceName,
  418. SERVICE_QUERY_STATUS)))
  419. {
  420. SERVICE_STATUS service_status;
  421. ZeroMemory(&service_status, sizeof(service_status));
  422. if( QueryServiceStatus(service_handle, &service_status) != 0 )
  423. {
  424. *lpStatus = service_status.dwCurrentState;
  425. }
  426. else
  427. {
  428. dwError = GetLastError();
  429. }
  430. if (CloseServiceHandle(service_handle) == FALSE)
  431. {
  432. _ASSERT(FALSE);
  433. //error closing service configuration manager
  434. }
  435. }
  436. else
  437. {
  438. dwError = GetLastError();
  439. }
  440. if (CloseServiceHandle(hManager) == FALSE)
  441. {
  442. //error closing service configuration manager
  443. _ASSERT(FALSE);
  444. }
  445. }
  446. else
  447. {
  448. dwError = GetLastError();
  449. }
  450. return dwError;
  451. }
  452. //////////////////////////////////////////////////////////////////////////_/_//
  453. //////////////////////////////////////////////////////////////////////////_/_//
  454. // DWORD GetServiceStatus_Enum (LPCTSTR aServiceName, LPDWORD lpStatus);
  455. //
  456. // Description: This function returns the status of the service named.
  457. // using the Win32 API call EnumServicesStatus(). This call
  458. // requires the mimimum access privileges but is the most
  459. // inefficient accurate way to retrieve the service staus.
  460. //
  461. // Parameters:
  462. //
  463. // IN
  464. // LPCTSTR aServiceName :- The name of the service
  465. //
  466. // OUT
  467. // LPDWORD lpStatus :- The service status
  468. //
  469. // Return Value: Returns a Win32 error code. ERROR_SUCCESS on success.
  470. //
  471. DWORD GetServiceStatus_Enum (LPCTSTR aServiceName, LPDWORD lpStatus)
  472. {
  473. DWORD dwError = ERROR_SUCCESS;
  474. SC_HANDLE hManager;
  475. _ASSERT( NULL != lpStatus );
  476. *lpStatus = SERVICE_STOPPED;
  477. hManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT );
  478. if ( NULL != hManager )
  479. {
  480. SC_HANDLE hService = OpenService( hManager, aServiceName, SERVICE_QUERY_STATUS );
  481. if ( NULL != hService )
  482. {
  483. SERVICE_STATUS ss;
  484. BOOL bRet = QueryServiceStatus( hService, &ss );
  485. if ( bRet )
  486. {
  487. *lpStatus = ss.dwCurrentState;
  488. }
  489. else
  490. {
  491. dwError = GetLastError( );
  492. }
  493. CloseServiceHandle( hService );
  494. // what do you do if this fails?
  495. }
  496. else
  497. {
  498. dwError = GetLastError( );
  499. }
  500. CloseServiceHandle( hManager );
  501. // what do you do if this fails?
  502. }
  503. else
  504. {
  505. dwError = GetLastError( );
  506. }
  507. return dwError;
  508. }
  509. //////////////////////////////////////////////////////////////////////////_/_//
  510. //////////////////////////////////////////////////////////////////////////_/_//
  511. // DWORD ManageService (LPCTSTR aServiceName,
  512. // DWORD aDesiredSCAccess,
  513. // DWORD aDesiredServiceAccess,
  514. // DWORD aAction,
  515. // BOOL bWait,
  516. // DWORD aWaitStatus
  517. // LPDWORD lpStatus);
  518. //
  519. // Description: This function opens the service named and performs the
  520. // specified control request on the given service. The
  521. // function optionally waits on the service to enter the
  522. // specified status.
  523. //
  524. // Additional Information:
  525. //
  526. // Parameters:
  527. //
  528. // LPCTSTR aServiceName :- The name of the service
  529. //
  530. // DWORD aDesiredSCAccess :- The access to use to open the service control
  531. // manager.
  532. //
  533. // DWORD aDesiredServiceAccess :- The access to use to open the service.
  534. //
  535. // DWORD aAction :- Specifies the requested control code.
  536. //
  537. // BOOL bWait :- TRUE specifies that this process should wait for the service
  538. // to reach the state identified by aWaitStatus.
  539. //
  540. // DWORD aWaitStatus :- The service state to wait for.
  541. //
  542. // OUT
  543. // LPDWORD lpStatus :- The service status
  544. //
  545. // Return Value: Returns a Win32 error code. ERROR_SUCCESS on success.
  546. //
  547. DWORD ManageService (LPCTSTR aServiceName,
  548. DWORD aDesiredSCAccess,
  549. DWORD aDesiredServiceAccess,
  550. DWORD aAction,
  551. BOOL bWait,
  552. DWORD aWaitStatus,
  553. LPDWORD lpStatus)
  554. {
  555. DWORD dwError = ERROR_SUCCESS;
  556. SC_HANDLE hManager = NULL;
  557. *lpStatus = SERVICE_STOPPED;
  558. if ((hManager = OpenSCManager(NULL, NULL, aDesiredSCAccess)) != NULL) {
  559. SC_HANDLE service_handle = NULL;
  560. if ((service_handle = OpenService(hManager,
  561. aServiceName,
  562. aDesiredServiceAccess)) != NULL) {
  563. SERVICE_STATUS service_status;
  564. ZeroMemory(&service_status, sizeof(service_status));
  565. if (ControlService(service_handle,
  566. aAction,
  567. &service_status) == TRUE) {
  568. //OK we should now know the current state
  569. if (bWait == TRUE) {
  570. if (WaitForServiceStatus(service_handle, aWaitStatus) == TRUE) {
  571. *lpStatus = aWaitStatus;
  572. }
  573. else {
  574. dwError = GetServiceStatus_Enum(aServiceName,lpStatus);
  575. }
  576. }
  577. else {
  578. *lpStatus = service_status.dwCurrentState;
  579. }
  580. }
  581. else {
  582. dwError = GetLastError();
  583. }
  584. if (CloseServiceHandle(service_handle) == FALSE) {
  585. _ASSERT(FALSE);
  586. //error closing service configuration manager
  587. }
  588. }
  589. else {
  590. dwError = GetLastError();
  591. }
  592. if (CloseServiceHandle(hManager) == FALSE) {
  593. //error closing service configuration manager
  594. _ASSERT(FALSE);
  595. }
  596. }
  597. else
  598. {
  599. dwError = GetLastError();
  600. }
  601. return(dwError);
  602. }
  603. //////////////////////////////////////////////////////////////////////////_/_//
  604. //////////////////////////////////////////////////////////////////////////_/_//
  605. // void ConfigureService (BOOL aSetToAutoStartBool);
  606. //
  607. // Description: This function sets the UPS service configuration to either
  608. // automatic or manual.
  609. //
  610. // Additional Information:
  611. //
  612. // Parameters:
  613. //
  614. // BOOL aSetToAutoStartBool :- TRUE for automatic. FALSE for manual.
  615. //
  616. // Return Value: None
  617. //
  618. void ConfigureService (BOOL aSetToAutoStartBool) {
  619. SC_HANDLE hSCM = 0;
  620. if ((hSCM = OpenSCManager(NULL, NULL, GENERIC_READ | GENERIC_EXECUTE)) != NULL) {
  621. SC_LOCK hLock = 0;
  622. if ((hLock = LockServiceDatabase(hSCM)) != NULL) {
  623. SC_HANDLE hService = 0;
  624. if ((hService = OpenService(hSCM, UPS_SERVICE_NAME, SERVICE_CHANGE_CONFIG)) != NULL) {
  625. DWORD dwStartType = 0;
  626. dwStartType = (aSetToAutoStartBool == TRUE) ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
  627. ChangeServiceConfig(hService,
  628. SERVICE_NO_CHANGE,
  629. dwStartType,
  630. SERVICE_NO_CHANGE,
  631. NULL,
  632. NULL,
  633. NULL,
  634. NULL,
  635. NULL,
  636. NULL,
  637. NULL);
  638. CloseServiceHandle(hService);
  639. }//end Open
  640. UnlockServiceDatabase(hLock);
  641. }//end Lock
  642. CloseServiceHandle(hSCM);
  643. }//end OpenSCM
  644. }
  645. //////////////////////////////////////////////////////////////////////////_/_//
  646. //////////////////////////////////////////////////////////////////////////_/_//
  647. // void AddActiveDataState (DWORD aBitToSet);
  648. //
  649. // Description: This function adds the given bit to current active data state.
  650. // The active data state is the state of the current UPS data set.
  651. // The UPS data set can include SERVICE_DATA_CHANGE and
  652. // CONFIG_DATA_CHANGE which signify that the service data like UPS
  653. // vendor, model name, etc, has changed. SERVICE_DATA_CHANGE is
  654. // for data the require the service to be restarted when changed.
  655. // CONFIG_DATA_CHANGE is for data that has changed but that does
  656. // not require a service restart.
  657. //
  658. // Additional Information:
  659. //
  660. // Parameters:
  661. //
  662. // DWORD aBitToSet :- The bit to set. Can be either SERVICE_DATA_CHANGE or
  663. // CONFIG_DATA_CHANGE.
  664. //
  665. // Return Value: None
  666. //
  667. void AddActiveDataState (DWORD aBitToSet) {
  668. g_CurrentActiveDataState |= aBitToSet;
  669. }
  670. //////////////////////////////////////////////////////////////////////////_/_//
  671. //////////////////////////////////////////////////////////////////////////_/_//
  672. // DWORD GetActiveDataState (void);
  673. //
  674. // Description: This function returns the current value of the active data
  675. // set. This value should be & with SERVICE_DATA_CHANGE and
  676. // CONFIG_DATA_CHANGE to determine the current active data state.
  677. //
  678. // Additional Information:
  679. //
  680. // Parameters: None
  681. //
  682. // Return Value: Returns the current active data state.
  683. //
  684. DWORD GetActiveDataState (void) {
  685. return(g_CurrentActiveDataState);
  686. }
  687. //////////////////////////////////////////////////////////////////////////_/_//
  688. //////////////////////////////////////////////////////////////////////////_/_//
  689. // void SetActiveDataState (DWORD aNewValue);
  690. //
  691. // Description: This function replaces the current value of the active data
  692. // state.
  693. //
  694. // Additional Information:
  695. //
  696. // Parameters:
  697. //
  698. // DWORD aNewValue :- The new value for the active data state.
  699. //
  700. // Return Value: None
  701. //
  702. void SetActiveDataState (DWORD aNewValue) {
  703. g_CurrentActiveDataState = aNewValue;
  704. }