-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIdentDService.bas
106 lines (79 loc) · 6.06 KB
/
IdentDService.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "IdentDService.bi"
Const MaxWaitHint As DWORD = 3000
Function EntryPoint Alias "EntryPoint"()As Integer
Dim DispatchTable(1) As SERVICE_TABLE_ENTRY = Any
DispatchTable(0).lpServiceName = @ServiceName
DispatchTable(0).lpServiceProc = @SvcMain
DispatchTable(1).lpServiceName = 0
DispatchTable(1).lpServiceProc = 0
If StartServiceCtrlDispatcher(@DispatchTable(0)) = 0 Then
Return 1
End If
Return 0
End Function
Sub SvcMain( _
ByVal dwNumServicesArgs As DWORD, _
ByVal lpServiceArgVectors As LPWSTR ptr _
)
Dim Context As ServiceContext
Context.ServiceStatusHandle = RegisterServiceCtrlHandlerEx(@ServiceName, @SvcCtrlHandlerEx, @Context)
If Context.ServiceStatusHandle = 0 Then
Exit Sub
End If
Context.ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS
Context.ServiceStatus.dwServiceSpecificExitCode = 0
ReportSvcStatus(@Context, SERVICE_START_PENDING, NO_ERROR, MaxWaitHint)
ReportSvcStatus(@Context, SERVICE_START_PENDING, NO_ERROR, MaxWaitHint)
Scope
Dim IdentDInitializeResult As Integer = InitializeIdentD(@Context.IdentD)
If IdentDInitializeResult <> 0 Then
ReportSvcStatus(@Context, SERVICE_STOPPED, NO_ERROR, 0)
Exit Sub
End If
ReportSvcStatus(@Context, SERVICE_START_PENDING, NO_ERROR, MaxWaitHint)
End Scope
ReportSvcStatus(@Context, SERVICE_RUNNING, NO_ERROR, 0)
IdentDMainLoop(@Context.IdentD)
ReportSvcStatus(@Context, SERVICE_STOPPED, NO_ERROR, 0)
End Sub
Function SvcCtrlHandlerEx( _
ByVal dwCtrl As DWORD, _
ByVal dwEventType As DWORD, _
ByVal lpEventData As LPVOID, _
ByVal lpContext As LPVOID _
)As DWORD
Dim pServiceContext As ServiceContext Ptr = lpContext
Select Case dwCtrl
Case SERVICE_CONTROL_INTERROGATE
ReportSvcStatus(pServiceContext, pServiceContext->ServiceStatus.dwCurrentState, NO_ERROR, 0)
Case SERVICE_CONTROL_STOP
ReportSvcStatus(pServiceContext, SERVICE_STOP_PENDING, NO_ERROR, MaxWaitHint)
UninitializeIdentD(@pServiceContext->IdentD)
Case Else
Return ERROR_CALL_NOT_IMPLEMENTED
End Select
Return NO_ERROR
End Function
Sub ReportSvcStatus( _
ByVal lpContext As ServiceContext Ptr, _
ByVal dwCurrentState As DWORD, _
ByVal dwWin32ExitCode As DWORD, _
ByVal dwWaitHint As DWORD _
)
lpContext->ServiceStatus.dwCurrentState = dwCurrentState
lpContext->ServiceStatus.dwWin32ExitCode = dwWin32ExitCode
lpContext->ServiceStatus.dwWaitHint = dwWaitHint
Select Case dwCurrentState
Case SERVICE_STOPPED
lpContext->ServiceStatus.dwCheckPoint = 0
Case SERVICE_START_PENDING, SERVICE_STOP_PENDING
lpContext->ServiceCheckPoint += 1
lpContext->ServiceStatus.dwCheckPoint = lpContext->ServiceCheckPoint
lpContext->ServiceStatus.dwControlsAccepted = 0
Case SERVICE_RUNNING
lpContext->ServiceStatus.dwCheckPoint = 0
lpContext->ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP
End Select
SetServiceStatus(lpContext->ServiceStatusHandle, @lpContext->ServiceStatus)
End Sub
EntryPoint()