ServiceInstaller.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /****************************** Module Header ******************************\
  2. * Module Name: ServiceInstaller.h
  3. * Project: CppWindowsService
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * The file declares functions that install and uninstall the service.
  7. *
  8. * This source is subject to the Microsoft Public License.
  9. * See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL.
  10. * All other rights reserved.
  11. *
  12. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  13. * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  15. \***************************************************************************/
  16. #pragma once
  17. #include <string>
  18. //
  19. // FUNCTION: InstallService
  20. //
  21. // PURPOSE: Install the current application as a service to the local
  22. // service control manager database.
  23. //
  24. // PARAMETERS:
  25. // * pszServiceName - the name of the service to be installed
  26. // * pszDisplayName - the display name of the service
  27. // * dwStartType - the service start option. This parameter can be one of
  28. // the following values: SERVICE_AUTO_START, SERVICE_BOOT_START,
  29. // SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START.
  30. // * pszDependencies - a pointer to a double null-terminated array of null-
  31. // separated names of services or load ordering groups that the system
  32. // must start before this service.
  33. // * pszAccount - the name of the account under which the service runs.
  34. // * pszPassword - the password to the account name.
  35. //
  36. // NOTE: If the function fails to install the service, it prints the error
  37. // in the standard output stream for users to diagnose the problem.
  38. //
  39. // modified for ZT1 to return an error or empty string on success
  40. std::string InstallService(PSTR pszServiceName,
  41. PSTR pszDisplayName,
  42. DWORD dwStartType,
  43. PSTR pszDependencies,
  44. PSTR pszAccount,
  45. PSTR pszPassword);
  46. //
  47. // FUNCTION: UninstallService
  48. //
  49. // PURPOSE: Stop and remove the service from the local service control
  50. // manager database.
  51. //
  52. // PARAMETERS:
  53. // * pszServiceName - the name of the service to be removed.
  54. //
  55. // NOTE: If the function fails to uninstall the service, it prints the
  56. // error in the standard output stream for users to diagnose the problem.
  57. //
  58. // Also modified to return rather than print errors
  59. std::string UninstallService(PSTR pszServiceName);