原理:利用python的win32模块,注册服务,让代码在后台运行,检测光盘并拷贝文件
启动的方法就是直接在cmd下,main.py install ,然后去windows 的服务下就可以看到The smallestpossible Python Service 这个服务,你可以启动,停止,还可以设置成开机自动启动。启动服务后,会自动检测光盘并在后台拷贝文件
main.py
import win32serviceutil
import win32service
import win32event
import CopyDvd2Hard
class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "The smallest possible Python Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop process.