00001 #ifndef WINSERVICE_H
00002 #define WINSERVICE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifdef __cplusplus
00012 extern "C"
00013 {
00014
00015 #endif
00016
00017
00018
00019
00020 #define REGISTER_SERVICE 0
00021 #define UN_REGISTER_SERVICE 1
00022 #define RUN_AS_SERVICE 2
00023 #define RUN_AS_CONSOLE 3
00024
00025
00026
00027
00028
00029 #define SERVICE_ERROR_NONE 0
00030 #define SERVICE_ERROR_SCM_OPEN 1
00031 #define SERVICE_ERROR_CREATE_SERVICE 2
00032 #define SERVICE_ERROR_CREATE_REGISTRY_ENTRIES 3
00033 #define SERVICE_ERROR_OPEN_SERVICE 4
00034
00035
00036
00037
00038
00039
00040 #define DISPLAY_MSG 0x00000064L
00041
00042
00043
00044
00045 #define SCM_WAIT_INTERVAL 7000
00046
00047
00048
00049
00050 #define MAX_STR_SIZE 1024
00051
00052
00053
00054
00055 extern BOOL g_fRunningAsService;
00056
00057
00058
00059
00060 typedef struct _InputParams
00061 {
00062 DWORD Argc;
00063 LPTSTR *Argv;
00064 } InputParams;
00065
00066
00067
00068
00069
00070
00071
00072
00073 int RegisterService (LPCTSTR lpszServiceName,
00074 LPCTSTR lpszServiceDisplayName,
00075 LPCTSTR lpszServiceDescription, InputParams * StartUpArg, int quiet);
00076
00077
00078
00079
00080 int UnregisterService (LPCSTR lpszServiceName, int quiet);
00081
00082
00083
00084
00085 INT ParseCmdLineForServiceOption (INT argc, TCHAR * argv[], int *quiet);
00086
00087
00088
00089
00090 VOID WriteToEventLog (WORD wType, LPCTSTR pszFormat, ...);
00091
00092
00093
00094
00095 VOID DisplayError (LPCTSTR pszTitle, int quite);
00096
00097
00098
00099
00100 static BOOL UpdateServiceStatus (DWORD dwStatus, DWORD dwErrorCode,
00101 DWORD dwWaitHint);
00102
00103
00104
00105
00106 static BOOL ReportCurrentServiceStatus (VOID);
00107
00108
00109
00110
00111
00112 VOID WINAPI ServiceMain (DWORD argc, LPTSTR argv[]);
00113
00114
00115
00116
00117
00118 BOOL RunAsService (INT (*ServiceFunction) (INT, LPTSTR *));
00119
00120
00121
00122
00123 VOID WINAPI ControlHandler (DWORD dwControl);
00124
00125
00126
00127
00128 VOID ProcessServiceStop (VOID);
00129
00130
00131
00132
00133 VOID ProcessServicePause (VOID);
00134
00135
00136
00137
00138 VOID ProcessServiceContinue (VOID);
00139
00140
00141
00142
00143 VOID ProcessServiceInterrogate (VOID);
00144
00145
00146
00147
00148 BOOL SetSimpleSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr);
00149
00150
00151
00152
00153 VOID FreeSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr);
00154
00155
00156
00157
00158 DWORD WINAPI ThreadFunction (LPVOID lpParam);
00159
00160
00161
00162
00163
00164 VOID RegisterStopFunction (VOID (*StopFunc) (VOID));
00165
00166 #ifdef __cplusplus
00167 }
00168 #endif
00169 #endif
00170