00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __UT_NTService_h__
00020 #define __UT_NTService_h__
00021
00022 #include <windows.h>
00023
00024 #include "UT_API.h"
00025 #include "UT_Defines.h"
00026
00027 #define UT_SERVICE_STOPPED 0
00028 #define UT_SERVICE_RUNNING 1
00029 #define UT_SERVICE_STARTING 2
00030
00031
00032
00033 #define SERVICE_CONTROL_USER 128
00034
00035
00036
00037 #define MB_SERVICE_NOTIFICATION 0x00200000L
00038
00039
00040 class UT_API UT_NTService
00041 {
00042 public:
00043 explicit UT_NTService(const char *serviceName);
00044 virtual ~UT_NTService();
00045
00046 virtual const char *getAboutString();
00047 virtual const char *getVersionString();
00048 virtual const char *getInstalledString();
00049
00050 const char *getServiceExeName();
00051 const char *getServiceUserName();
00052
00053 UT_Bool isInstalled();
00054 int isRunning();
00055
00056 UT_Bool logEvent(WORD type,
00057 DWORD id,
00058 const char* string1 = UT_NULL,
00059 const char* string2 = UT_NULL,
00060 const char* string3 = UT_NULL);
00061
00062 UT_Bool startService();
00063
00064 void setStatus(DWORD state);
00065
00066 UT_Bool initialize();
00067
00068 virtual void run();
00069
00070 virtual UT_Bool onInit();
00071 virtual void onStop();
00072 virtual void onInterrogate();
00073 virtual void onPause();
00074 virtual void onContinue();
00075 virtual void onShutdown();
00076 virtual void onUserLogout();
00077 virtual UT_Bool onUserControl(DWORD opcode);
00078
00079 void debugMsg(const char* format, ...);
00080 void userMsg(const char* format, ...);
00081 void userDisplayLastError();
00082 void userDisplayAdminError();
00083
00084 static void WINAPI serviceMain(DWORD argc, LPTSTR* argv);
00085 static void WINAPI handler(DWORD opcode);
00086
00087 HINSTANCE getHInstance() { return myHInstance; };
00088
00089
00090
00091 static UT_NTService* myThis;
00092
00093 char myServiceName[64];
00094 SERVICE_STATUS_HANDLE myServiceStatus;
00095 SERVICE_STATUS myStatus;
00096 UT_Bool myIsRunning;
00097
00098 protected:
00099 void userMessageBox(LPCSTR msg, LPCSTR title, UINT type);
00100
00101 static DWORD WINAPI msgBoxMain(LPVOID msgParam);
00102 static BOOL WINAPI logoutHandler(DWORD ctrlType);
00103 static BOOL CALLBACK EnumCloseProc(HWND hwnd, LPARAM lParam);
00104
00105 HINSTANCE myHInstance;
00106 HANDLE myEventSource;
00107 };
00108
00109 #endif // __UT_NTService_h__