python启动windows程序_Python开发windows服务程序并设置启动,python,开机

本文介绍了如何利用Python创建Windows服务程序,并设置为开机启动。首先需要安装pywin32和pyinstaller库。然后提供了一个通用的Python服务程序模板,通过SvcDoRun方法编写业务代码。最后,通过pyinstaller将Python脚本编译为exe文件,并使用命令行控制服务的安装、启动、停止和移除。
摘要由CSDN通过智能技术生成

1.环境设置

python要开发windows程序,首先必须先安装好pywin32,还要安装pyinstaller

pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple

2.编写代码,以下是通用的python编译成windows服务程序的模板,不要问我为什么,我也是网上找的,可在SvcDoRun编写自己的业务代码

#encoding=utf-8

import win32serviceutil

import win32service

import win32event

import os

import logging

import inspect

class PySerTest(win32serviceutil.ServiceFramework):

_svc_name_ = "PySerTest"

_svc_display_name_ = "Py Service Test"#服务显示的名称,可以自己修改

_svc_description_ = "This is a python service test code "//服务显示的描述

def __init__(self, args):

win32serviceutil.ServiceFramework.__init__(self, args)

self.hWaitStop = win32event.CreateEvent(None, 0, 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值