-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathService.cpp
More file actions
80 lines (65 loc) · 2.42 KB
/
Service.cpp
File metadata and controls
80 lines (65 loc) · 2.42 KB
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
/******************************************************************************************
Copyright 2013 Christian Roggia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************************/
// MODIFIED BY mic.ric.tor
#include "Service.h"
#include "5.h"
namespace sc { namespace service {
VOID ReportSvcStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
{
static DWORD dwCheckPoint = 1;
// Fill in the SERVICE_STATUS structure.
dwSvcStatus.dwCurrentState = dwCurrentState;
dwSvcStatus.dwWin32ExitCode = dwWin32ExitCode;
dwSvcStatus.dwWaitHint = dwWaitHint;
if(dwCurrentState == SERVICE_START_PENDING)
dwSvcStatus.dwControlsAccepted = 0;
else
dwSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
if(dwCurrentState == SERVICE_RUNNING || dwCurrentState == SERVICE_STOPPED)
dwSvcStatus.dwCheckPoint = 0;
else
dwSvcStatus.dwCheckPoint = dwCheckPoint++;
// Report the status of the service to the SCM.
SetServiceStatus(hSvcStatusHandle, &dwSvcStatus);
}
VOID WINAPI SvcCtrlHandler(DWORD dwCtrl)
{
if(dwCtrl == SERVICE_CONTROL_STOP)
{
ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
bSvcStopped = true;
ReportSvcStatus(dwSvcStatus.dwCurrentState, NO_ERROR, 0);
}
}
VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv)
{
hSvcStatusHandle = RegisterServiceCtrlHandlerW(L"wow32", SvcCtrlHandler);
if(hSvcStatusHandle)
{
dwSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
dwSvcStatus.dwServiceSpecificExitCode = 0;
ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
Run(TRUE);
ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
}
}
VOID SvcSleep(DWORD dwSeconds)
{
while( dwSeconds != 0 && !bSvcStopped )
{
Sleep(1000);
dwSeconds--;
}
}
}}