简体   繁体   English

如何让Windows了解我用Python编写的服务?

[英]How do I make Windows aware of a service I have written in Python?

In another question I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. 在我昨天发布的另一个问题中 ,我对如何在Windows中作为服务运行Python脚本提出了很好的建议。 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"). 我想知道的是:Windows如何了解可以在本机工具中管理的服务(“管理工具”中的“服务”窗口)。 I. e. I. e。 what is the Windows equivalent of putting a start/stop script in /etc/init.d under Linux? 什么是Windows在Linux下的/etc/init.d中放置启动/停止脚本?

Don't muck with the registry directly. 不要直接捣乱注册表。 User the SC command-line tool. 用户SC命令行工具。 Namely, SC CREATE 即,SC CREATE

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

Here is code to install a python-script as a service, written in python :) 这是安装python脚本作为服务的代码,用python编写:)

http://code.activestate.com/recipes/551780/ http://code.activestate.com/recipes/551780/

This post could also help you out: 这篇文章也可以帮助你:

http://essiene.blogspot.com/2005/04/python-windows-services.html http://essiene.blogspot.com/2005/04/python-windows-services.html

As with most "aware" things in Windows, the answer is "Registry". 与Windows中大多数“意识到”的东西一样,答案是“注册表”。

Take a look at this Microsoft Knowledge Base article: http://support.microsoft.com/kb/103000 请查看此Microsoft知识库文章: http//support.microsoft.com/kb/103000

Search for "A Win32 program that can be started by the Service Controller and that obeys the service control protocol." 搜索“可以由服务控制器启动并遵守服务控制协议的Win32程序”。 This is the kind of service you're interested in. 这是您感兴趣的服务类型。

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. 服务注册(KEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ myservice的内容)包含有关服务的信息,包括其可执行位置,失败时要做什么(停止操作系统?),在此之前必须启动哪些服务,它运行的用户是什么。

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. 对于服务控制协议,程序的main()应该调用Windows API调用,为服务的启动,停止,暂停设置回调。 What you do in those callbacks is all up to you. 你在那些回调中所做的一切都取决于你。

You can use srvany.exe from Windows NT Resource Kit to create a user defined service that will show up in the admin tools... 您可以使用Windows NT Resource Kit中的srvany.exe创建将在管理工具中显示的用户定义服务...

http://support.microsoft.com/kb/137890 http://support.microsoft.com/kb/137890

I am using this method to run tracd (a python script / server) for trac. 我正在使用此方法为trac运行tracd(python脚本/服务器)。

Here are some very clear instructions: http://www.tacktech.com/display.cfm?ttid=197 以下是一些非常明确的说明: http//www.tacktech.com/display.cfm?ttid = 197

It does require some registry editing (very minimal and easy) but will allow you to make any command line / script a windows service. 它确实需要一些注册表编辑(非常简单和简单),但允许您使任何命令行/脚本成为Windows服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用Linux编写的django项目如何运行?我有Windows吗? - How do I run a django project when it is written in Linux, do I have Windows? 如何让ipython了解对自写模块所做的更改? - How do I make ipython aware of changes made to a selfwritten module? 如何使cygwin意识到有思想的python? - How can I make cygwin aware of enthought python? 如何在Python中组合时区感知日期和时间? - How do I combine a timezone aware date and time in Python? 如何将 3 个数字与在 Python 中仅采用 2 个变量的函数与我编写的代码进行比较 - How do I compare 3 numbers with a function that takes only 2 variables in Python with a code that I have written 如何查看用Python编写的HTML? - How can I view an HTML that I have written in Python? 如何在 Windows 上的 Python 中连接到经过 kerberos 身份验证的 REST 服务 - How do I connect to a kerberos authenticated REST service in Python on Windows 我已经为数字的collat​​z模式编写了一个python代码,我想计算达到1所需的步骤数。我该怎么做? - I have written a python code for the collatz pattern for number and I want to count the number of steps it took to reach 1. How can I do it? 如何使Gnome面板小程序(用python编写)为每个实例存储单独的设置? - How do I make a Gnome Panel applet (written in python) store seperate settings for each instance? 如何在注销后生成Python脚本(作为服务安装)? - How do I make a Python script (installed as a service) survive a logout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM