在 Windows 中将 python .py 作为服务启动

编程入门 行业动态 更新时间:2024-10-14 22:19:31
本文介绍了在 Windows 中将 python .py 作为服务启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我已经创建了一个 Windows 服务来启动一个 .py 脚本.

I've created a windows service to start a .py script.

sc create "Maraschino" binPath= "C:\HTPC\Maraschino\maraschino-cherrypy.py" DisplayName=    "Maraschino" depend= "Tcpip"

然后我添加了一个注册表项来链接 .py 以使用 python.exe 打开

Then I've added a registry key to link the .py to open using python.exe

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Maraschino\Parameters]
"AppDirectory"="C:\\Python27"
"Application"="C:\\Python27\\python.exe C:\\HTPC\\Maraschino\\maraschino-cherrypy.py"

但是,当我尝试启动该服务时,我收到错误 193 0xc1,当 Google 搜索显示它不是我正在尝试启动的有效 exe 时.我知道它不是 .exe 而是 .py 并将它链接到 python.exe 打开应该解决这个问题,但我犯了一个错误.有没有人知道我在链接脚本以使用 python.exe 时可能做错了什么

However when I try start the service I get Error 193 0xc1 which when googled revealed that it isn't a valid exe I'm trying to start. I know its not an .exe but a .py and linking it to open with python.exe should fix this but I'm making an error. Does anyone have any insight into what I might be doing wrong when linking the script to use python.exe

谢谢

推荐答案

您可以使用 srvany.exe 来执行此操作,这是 Microsoft 专门用于此类任务的工具.

You can do this using the srvany.exe, which is a tool from Microsoft dedicated for this kind of tasks.

首先,下载并安装 Windows Resource Kit.注意:您只需要 srvany.exe,它适用于所有版本的 Windows.

First, download and install the Windows Resource Kit. Note: You only need srvany.exe, which works on all versions of Windows.

假设 Windows Resource Kit 安装在 C:\Program Files\Windows Resource Kits\ 运行:

Presuming that the Windows Resource Kit was installed at C:\Program Files\Windows Resource Kits\ run:

sc create "[YourService]" binPath= "C:\Program Files\Windows Resource Kits\srvany.exe"

现在,运行 regedit.

在注册表编辑器对话框中选择HKEY_LOCAL_MACHINE >系统>当前控制集 >服务 >[您的服务]

In the Registry Editor dialog select HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Services > [YourService]

选择 [YourService] 后,点击工具栏中的编辑">新建">键".

With [YourService] selected, hit Edit > New > Key from the toolbar.

输入参数并按回车键.

从工具栏中选择编辑">新建">字符串值".

From the toolbar select Edit > New > String Value.

输入应用程序并按回车键.

右键单击应用程序并选择修改.

Right-click Application and select Modify.

C:\Python27\python.exe C:\[YourServicePath].py

点击确定按钮.

还有繁荣!你有一个不错的新服务.

And boom! you have a nice new service.

这篇关于在 Windows 中将 python .py 作为服务启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 12:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1116662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   Windows   py   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!