1 | // ******************************************************************************************************************************************************************************
|
---|
2 | // Aplicación HIDRA
|
---|
3 | // Copyright 2003-2005 José Manuel Alonso. Todos los derechos reservados.
|
---|
4 | // Fichero: servicio.h
|
---|
5 | // Descripción:
|
---|
6 | // Este proyecto implementa el servicio hidra en un ordenador con plataforma windows NT. Este fichero aporta las funciones para crear el servicio
|
---|
7 | // ******************************************************************************************************************************************************************************
|
---|
8 | //____________________________________________________________________________________________________________________________
|
---|
9 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
---|
10 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
---|
11 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
---|
12 | // PARTICULAR PURPOSE.
|
---|
13 | //
|
---|
14 | // Copyright (C) 1993-1997 Microsoft Corporation. All Rights Reserved.
|
---|
15 | //
|
---|
16 | // MODULE: service.h
|
---|
17 | // AUTHOR: Craig Link
|
---|
18 | //
|
---|
19 | // Comments: The use of this header file and the accompanying service.c
|
---|
20 | // file simplifies the process of writting a service. You as a developer
|
---|
21 | // simply need to follow the TODO's outlined in this header file, and
|
---|
22 | // implement the ServiceStart() and ServiceStop() functions.
|
---|
23 | //
|
---|
24 | // There is no need to modify the code in service.c. Just add service.c
|
---|
25 | // to your project and link with the following libraries...
|
---|
26 | //
|
---|
27 | // libcmt.lib kernel32.lib advapi.lib shell32.lib
|
---|
28 | //
|
---|
29 | // This code also supports unicode. Be sure to compile both service.c and
|
---|
30 | // and code #include "service.h" with the same Unicode setting.
|
---|
31 | //
|
---|
32 | // Upon completion, your code will have the following command line interface
|
---|
33 | //
|
---|
34 | // <service exe> -? to display this list
|
---|
35 | // <service exe> -install to install the service
|
---|
36 | // <service exe> -remove to remove the service
|
---|
37 | // <service exe> -debug <params> to run as a console app for debugging
|
---|
38 | //
|
---|
39 | // Note: This code also implements Ctrl+C and Ctrl+Break handlers
|
---|
40 | // when using the debug option. These console events cause
|
---|
41 | // your ServiceStop routine to be called
|
---|
42 | //
|
---|
43 | // Also, this code only handles the OWN_SERVICE service type
|
---|
44 | // running in the LOCAL_SYSTEM security context.
|
---|
45 | //
|
---|
46 | // To control your service ( start, stop, etc ) you may use the
|
---|
47 | // Services control panel applet or the NET.EXE program.
|
---|
48 | //
|
---|
49 | // To aid in writing/debugging service, the
|
---|
50 | // SDK contains a utility (MSTOOLS\BIN\SC.EXE) that
|
---|
51 | // can be used to control, configure, or obtain service status.
|
---|
52 | // SC displays complete status for any service/driver
|
---|
53 | // in the service database, and allows any of the configuration
|
---|
54 | // parameters to be easily changed at the command line.
|
---|
55 | // For more information on SC.EXE, type SC at the command line.
|
---|
56 | //
|
---|
57 | //____________________________________________________________________________________________________________________________
|
---|
58 | #include <windows.h>
|
---|
59 | #include <stdio.h>
|
---|
60 | #include <stdlib.h>
|
---|
61 | #include <process.h>
|
---|
62 | #include <tchar.h>
|
---|
63 | #include "registrow.h"
|
---|
64 |
|
---|
65 | #ifndef _SERVICE_H
|
---|
66 | #define _SERVICE_H
|
---|
67 |
|
---|
68 | #ifdef __cplusplus
|
---|
69 | extern "C" {
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | // name of the executable
|
---|
73 | #define SZAPPNAME "ogAdmWinClient"
|
---|
74 | // internal name of the service
|
---|
75 | #define SZSERVICENAME "Cliente Opengnsys"
|
---|
76 | // displayed name of the service
|
---|
77 | #define SZSERVICEDISPLAYNAME "Cliente Opengnsys"
|
---|
78 | // list of service dependencies - "dep1\0dep2\0\0"
|
---|
79 | #define SZDEPENDENCIES ""
|
---|
80 |
|
---|
81 | #define SERVIDOR_DEFAULT "0.0.0.0"
|
---|
82 | #define PUERTO_DEFAULT "2003"
|
---|
83 | #define IPLOCAL_DEFAULT "0.0.0.0"
|
---|
84 |
|
---|
85 | #define CHKREGISTRY(f) if (!(f)) { return 0;}
|
---|
86 | #define RMVREGISTRY(f) if (!(f)) { return 0;}
|
---|
87 | #define TOMAPARAMINT(p) p=atoi(&argv[i][3]);
|
---|
88 | #define TOMAPARAMSTR(p) strcpy(p,&argv[i][3]);
|
---|
89 |
|
---|
90 | #define HIVE HKEY_LOCAL_MACHINE // Rama del registro donde estarán los parametros de conexión
|
---|
91 | #define BASEKEY "SOFTWARE\\opengnsys" // Key del registro para parametros de conexión
|
---|
92 | #define BASE "SOFTWARE\\opengnsys\\cliente" // SubKey del registro para parametros de conexión
|
---|
93 |
|
---|
94 | //____________________________________________________________________________________________________________________________
|
---|
95 | //
|
---|
96 | SERVICE_STATUS ssStatus; // current status of the service
|
---|
97 | SERVICE_STATUS_HANDLE sshStatusHandle;
|
---|
98 | //
|
---|
99 | //____________________________________________________________________________________________________________________________
|
---|
100 | // ServiceStart()must be defined by in your code.
|
---|
101 | // The service should use ReportStatusToSCMgr to indicate
|
---|
102 | // progress. This routine must also be used by StartService()
|
---|
103 | // to report to the SCM when the service is running.
|
---|
104 | //
|
---|
105 | // If a ServiceStop procedure is going to take longer than
|
---|
106 | // 3 seconds to execute, it should spawn a thread to
|
---|
107 | // execute the stop code, and return. Otherwise, the
|
---|
108 | // ServiceControlManager will believe that the service has
|
---|
109 | // stopped responding
|
---|
110 | //
|
---|
111 | //____________________________________________________________________________________________________________________________
|
---|
112 | VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv);
|
---|
113 | VOID ServiceStop();
|
---|
114 | //____________________________________________________________________________________________________________________________
|
---|
115 | // The following are procedures which
|
---|
116 | // may be useful to call within the above procedures,
|
---|
117 | // but require no implementation by the user.
|
---|
118 | // They are implemented in service.c
|
---|
119 | //
|
---|
120 | // FUNCTION: ReportStatusToSCMgr()
|
---|
121 | //
|
---|
122 | // PURPOSE: Sets the current status of the service and
|
---|
123 | // reports it to the Service Control Manager
|
---|
124 | //
|
---|
125 | // PARAMETERS:
|
---|
126 | // dwCurrentState - the state of the service
|
---|
127 | // dwWin32ExitCode - error code to report
|
---|
128 | // dwWaitHint - worst case estimate to next checkpoint
|
---|
129 | //
|
---|
130 | // RETURN VALUE:
|
---|
131 | // TRUE - success
|
---|
132 | // FALSE - failure
|
---|
133 | //____________________________________________________________________________________________________________________________
|
---|
134 | BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint);
|
---|
135 | //____________________________________________________________________________________________________________________________
|
---|
136 | // FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
|
---|
137 | //
|
---|
138 | // PURPOSE: Allows any thread to log an error message
|
---|
139 | //
|
---|
140 | // PARAMETERS:
|
---|
141 | // lpszMsg - text for message
|
---|
142 | //
|
---|
143 | // RETURN VALUE:
|
---|
144 | // none
|
---|
145 | //____________________________________________________________________________________________________________________________
|
---|
146 | void AddToMessageLog(LPTSTR lpszMsg);
|
---|
147 | //____________________________________________________________________________________________________________________________
|
---|
148 | //
|
---|
149 | #ifdef __cplusplus
|
---|
150 | }
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | #endif
|
---|