在another question我昨天发布了一篇关于Python脚本如何作为Windows服务运行的非常好的建议。我还想知道的是:Windows如何意识到可以在本地工具中管理的服务(“管理工具”中的“服务”窗口)。 I. e。在Linux下,在/etc/init.d中将启动/停止脚本放在什么位置等同于Windows?如何让Windows意识到我用Python编写的服务?
回答
与Windows中最“意识到”的东西,答案是“注册表”。
看看这Microsoft知识库文章在:http://support.microsoft.com/kb/103000
搜索“可以由服务控制器启动的并且服从服务控制协议Win32程序。”这是您感兴趣的服务类型。
服务注册(KEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services的内容为 \ myservice)包含有关服务的信息,包括其可执行位置等信息,它会失败(停止操作系统?),必须在此之前启动哪些服务,它运行的是哪个用户。
对于服务控制协议,您的程序的main()应该调用Windows API调用,为您的服务设置启动,停止和暂停的回调。你在这些回调中所做的全部取决于你。
这里是代码安装Python的脚本作为一种服务,用Python编写的:)
http://code.activestate.com/recipes/551780/
这篇文章也可以帮助你:
http://essiene.blogspot.com/2005/04/python-windows-services.html
可以使用SRVANY.EXE从Windows NT资源工具包来创建用户定义的服务,将在管理工具中显示...
http://support.microsoft.com/kb/137890
我使用这种方法来运行tracd( trac的一个python脚本/服务器)。
这里有一些非常明确的指示:http://www.tacktech.com/display.cfm?ttid=197
它确实需要一些注册表编辑(非常小的,容易),但将允许你进行任何命令行/脚本Windows服务。
不要与注册表直接混淆。用户使用SC命令行工具。即SC创建
DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services. USAGE: sc [command] [service name] ... The option has the form "\\ServerName" Further help on commands can be obtained by typing: "sc [command]" Commands: query-----------Queries the status for a service, or enumerates the status for types of services. queryex---------Queries the extended status for a service, or enumerates the status for types of services. start-----------Starts a service. pause-----------Sends a PAUSE control request to a service. interrogate-----Sends an INTERROGATE control request to a service. continue--------Sends a CONTINUE control request to a service. stop------------Sends a STOP request to a service. config----------Changes the configuration of a service (persistant). description-----Changes the description of a service. failure---------Changes the actions taken by a service upon failure. qc--------------Queries the configuration information for a service. qdescription----Queries the description for a service. qfailure--------Queries the actions taken by a service upon failure. delete----------Deletes a service (from the registry). create----------Creates a service. (adds it to the registry). control---------Sends a control to a service. sdshow----------Displays a service's security descriptor. sdset-----------Sets a service's security descriptor. GetDisplayName--Gets the DisplayName for a service. GetKeyName------Gets the ServiceKeyName for a service. EnumDepend------Enumerates Service Dependencies. The following commands don't require a service name: sc boot------------(ok | bad) Indicates whether the last boot should be saved as the last-known-good boot configuration Lock------------Locks the Service Database QueryLock-------Queries the LockStatus for the SCManager Database EXAMPLE: sc start MyService
- 1. 如何获取用C#编写的Windows服务中的ServiceName?
- 2. 我如何编写一个Windows服务来管理其他的Windows服务?(我能吗?)
- 3. 如何调试在VS2008中用VC++编写的Windows服务?
- 4. 如何编写jPOS服务
- 5. 如何让ASP.NET识别我的自定义服务器控件?
- 6. 如何让HSQLDB成为Windows服务?
- 7. 如何让WiX删除Windows服务?
- 8. 如何使用soap编写web服务
- 9. 如何使用CPython编写服务?
- 10. 如何使用cakephp编写Web服务
- 11. 索赔意识WCF服务
- 12. 如何让我的Windows服务以特定间隔运行?
- 13. 如何让我的本地服务器区分大小写?
- 14. 如何让ipython意识到对自写模块所做的更改?
- 15. 如何让我的应用程序服务器CPU达到100%?
- 16. 如何为Windows服务程序编写OnStart函数?
- 17. windows server 2008:如何识别谁登录到服务器
- 18. 如何让python识别我正在使用的窗口?
- 19. 用Java编写的OPC服务器让我的Java UI停止工作
- 20. 如何使用python从localhost连接到windows azure mysql服务器?
- 21. 如何使用C#.NET中的Windows服务调用Windows服务?
- 22. 如何让用户在我的服务器上运行任意源代码
- 23. Windows服务意外终止
- 24. 如何查看依赖于Python服务的Windows服务?
- 25. 由C#编写的Windows服务使用的类库程序集#
- 26. 如何安排我的Windows服务?
- 27. 如何让itemtemplate意识到它的包含模板?
- 28. Windows服务输出写入到文件
- 29. 如何编写python HTTP服务器以侦听多个端口?
- 30. Alexa没有意识到我的意图
注册表黑客是不良形式。其实,可怕的形式。 .py应接受-install cmd行参数并将其自身安装为服务,使用已发布的API和方法(例如,不通过直接注册表访问) – Jonesome 2013-07-24 22:58:37