-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinServiceBase.py
More file actions
55 lines (36 loc) · 1.23 KB
/
WinServiceBase.py
File metadata and controls
55 lines (36 loc) · 1.23 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
import socket
import win32.lib.win32serviceutil as win32serviceutil
import win32.servicemanager as servicemanager
import win32.win32event as win32event
import win32.win32service as win32service
class SMWinServiceBase(win32serviceutil.ServiceFramework):
_svc_name_ = "SampleleService"
_svc_display_name_ = "Sample Service"
_svc_description_ = "Service Sample Description"
@classmethod
def parse_command_line(cls):
win32serviceutil.HandleCommandLine(cls)
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.stop()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
self.start()
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ""),
)
self.main()
def start(self):
pass
def stop(self):
pass
def main(self):
pass
if __name__ == "__main__":
SMWinServiceBase.parse_command_line()