/[cvs]/joko/TestArea/vb/NtServices/ServiceApp/FirstSteps/clsServiceControl.cls
ViewVC logotype

Annotation of /joko/TestArea/vb/NtServices/ServiceApp/FirstSteps/clsServiceControl.cls

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Jan 20 19:21:32 2003 UTC (21 years, 10 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
+ initial check-in

1 joko 1.1 VERSION 1.0 CLASS
2     BEGIN
3     MultiUse = -1 'True
4     Persistable = 0 'NotPersistable
5     DataBindingBehavior = 0 'vbNone
6     DataSourceBehavior = 0 'vbNone
7     MTSTransactionMode = 0 'NotAnMTSObject
8     END
9     Attribute VB_Name = "clsServiceControl"
10     Attribute VB_GlobalNameSpace = False
11     Attribute VB_Creatable = True
12     Attribute VB_PredeclaredId = False
13     Attribute VB_Exposed = False
14     Option Explicit
15    
16     ' a reference to a "NTService"-UserControl-Object
17     Dim refNTServiceCtrl As NTService.NTService
18     ' a reference to a Timer-Object
19     Dim refTimer As Timer
20     ' the interval
21     Dim cInterval As Long
22    
23     Friend Sub setRefs(ByRef rNTService As NTService.NTService, ByRef rTimer As Timer)
24     Set refNTServiceCtrl = rNTService
25     Set refTimer = rTimer
26     End Sub
27    
28     Friend Sub setInterval(lngInterval As Long)
29     cInterval = lngInterval
30     End Sub
31    
32     Friend Sub doStart(Optional runAsService As Boolean = False)
33    
34     ' determine if we should run us as a "normal" application
35     If Not runAsService Then
36     refNTServiceCtrl.Debug = True
37     setCurrentStatus "Starting Application"
38     Else
39     setCurrentStatus "Starting Service"
40     End If
41    
42     ' some debug-breakpoint we don't know anything about (from example-code)
43     'Call DebugBreak
44    
45     On Error GoTo Err_Load
46    
47     ' initialize timer
48     setCurrentStatus "Loading configuration from Service"
49     Dim parmInterval As String
50     parmInterval = refNTServiceCtrl.GetSetting("Parameters", "TimerInterval", cInterval)
51     refTimer.Interval = CInt(parmInterval)
52    
53     ' enable Pause/Continue. Must be set before StartService is called or in design mode
54     setCurrentStatus "Enabling control mode"
55     refNTServiceCtrl.ControlsAccepted = svcCtrlPauseContinue
56    
57     ' connect service to Windows NT services controller
58     setCurrentStatus "Starting"
59     refNTServiceCtrl.StartService
60    
61     Call refNTServiceCtrl.LogEvent(svcMessageError, svcEventError, "started service")
62     Exit Sub
63    
64     Err_Load:
65     If refNTServiceCtrl.Interactive Then
66     MsgBox "[" & Err.Number & "] " & Err.Description
67     End
68     Else
69     Call refNTServiceCtrl.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
70     End If
71    
72     End Sub
73    
74     Friend Function doStop()
75     refNTServiceCtrl.StopService
76     End Function
77    
78     Friend Sub doDebugMode()
79     refNTServiceCtrl.Debug = True
80     End Sub
81    
82     Friend Sub doInstall()
83     Dim logMsg As String
84     Dim evType As Variant
85    
86     'refNTServiceCtrl.Debug = True
87    
88     ' enable interaction with desktop
89     refNTServiceCtrl.Interactive = True
90     'refNTServiceCtrl.Interactive = False
91    
92     ' install service
93     If refNTServiceCtrl.Install Then
94     Call refNTServiceCtrl.SaveSetting("Parameters", "TimerInterval", cInterval)
95     logMsg = refNTServiceCtrl.DisplayName & " installed successfully"
96     evType = SvcEventType.svcEventSuccess
97     Else
98     logMsg = refNTServiceCtrl.DisplayName & " failed to install"
99     evType = SvcEventType.svcEventError
100     End If
101    
102     ' log/display success
103     Call refNTServiceCtrl.LogEvent(evType, 0, logMsg)
104     If refNTServiceCtrl.Interactive Then
105     MsgBox logMsg
106     End If
107    
108     End
109     End Sub
110    
111     Friend Sub doUninstall()
112    
113     Dim logMsg As String
114     Dim evType As Variant
115    
116     If refNTServiceCtrl.Uninstall Then
117     logMsg = refNTServiceCtrl.DisplayName & " uninstalled successfully"
118     evType = SvcEventType.svcEventSuccess
119     Else
120     logMsg = refNTServiceCtrl.DisplayName & " failed to uninstall"
121     evType = SvcEventType.svcEventError
122     End If
123    
124     ' log/display success
125     Call refNTServiceCtrl.LogEvent(evType, 0, logMsg)
126     If refNTServiceCtrl.Interactive Then
127     MsgBox logMsg
128     End If
129    
130     End
131    
132     End Sub
133    

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed