如何使Windows知道我用Python编写的服务? [英] How do I make Windows aware of a service I have written in Python?

查看:90
本文介绍了如何使Windows知道我用Python编写的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个问题昨天我发布了一个很好的建议,关于如何在Windows中将Python脚本作为服务运行。我唯一想知道的是:Windows如何了解可以在本机工具(管理工具中的服务窗口)中管理的服务。即Windows与在Linux下将启动/停止脚本放在/etc/init.d中等效吗?

In another question I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is: How is Windows aware of the services that can be managed in the native tools ("services" window in "administrative tools"). I. e. what is the Windows equivalent of putting a start/stop script in /etc/init.d under Linux?

推荐答案

在Windows中知道事物,答案是注册表。

As with most "aware" things in Windows, the answer is "Registry".

请参阅以下Microsoft知识库文章: http://support.microsoft.com/kb/103000

Take a look at this Microsoft Knowledge Base article: http://support.microsoft.com/kb/103000

搜索可以由服务控制器启动的服从服务控制协议的Win32程序。

Search for "A Win32 program that can be started by the Service Controller and that obeys the service control protocol." This is the kind of service you're interested in.

服务注册(KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services的内容
\myservice) )包含有关该服务的信息,包括其可执行位置,发生故障(停止OS?)时应采取的措施,在此服务之前必须启动的服务,以什么用户身份运行等信息。

The service registration (contents of KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services \myservice) carries information about the service, including things like its executable location, what to do when it fails (halt the OS?), what services must be started before this one, what user it runs as.

关于服务控制协议,程序的main()应该调用Windows API调用,为服务的启动,停止和暂停设置回调。您在这些回调中所做的全部取决于您。

As to service control protocol, main() of your program is supposed to invoke a Windows API call, setting up callbacks for start, stop, pause for your service. What you do in those callbacks is all up to you.

这篇关于如何使Windows知道我用Python编写的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆