问题描述
限时送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:关键词]
发布评论