pywin32 설치
python -m pip install --upgrade pywin32
- 가상환경에서 설치하면 안됨.
가상 환경 외부에서는 COM 객체, 서비스 등을 설치하고자 할 때
python Script/pywin32_postinstall.py -install
[myservice.py]
import win32serviceutil
import ctypes
import time
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = 'MyService'
_svc_display_name_ = 'My Service'
is_running = False
def SvcStop(self):
OutputDebugString("MyService __SvcStop__")
self.is_running = False
def SvcDoRun(self):
self.is_running = True
while self.is_running:
OutputDebugString("MyService __loop__")
time.sleep(1)
if '__main__' == __name__:
win32serviceutil.HandleCommandLine(MyService)
import ctypes
import time
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = 'MyService'
_svc_display_name_ = 'My Service'
is_running = False
def SvcStop(self):
OutputDebugString("MyService __SvcStop__")
self.is_running = False
def SvcDoRun(self):
self.is_running = True
while self.is_running:
OutputDebugString("MyService __loop__")
time.sleep(1)
if '__main__' == __name__:
win32serviceutil.HandleCommandLine(MyService)
관리자 권한으로 PowerSell 실행
python myservice.py install
python myservice.py start
python myservice.py stop
댓글 없음:
댓글 쓰기