问题描述
我在普通命令提示符下通过 python win_service.py install 运行下面的代码,在那里我收到访问被拒绝的错误.
I am running the code below by python win_service.py install from the normal command prompt, where I get access denied error.
安装服务TestService
安装服务时出错:访问被拒绝.(5)
当我以管理员身份启动命令提示符时,我能够解决这个问题.
which I was able to resolve when I started the command prompt by starting as administrator.
我能够安装该服务,但无法启动该服务.
I was able to install the service, but I was unable to start the service.
已安装服务
启动服务TestService
启动服务时出错:服务没有及时响应启动或控制请求.
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "TestService"
_svc_display_name_ = "Test Service"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_,''))
self.main()
def main(self):
print "running"
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)
我做错了什么,有没有其他方法可以安装可以解决问题的服务以及如何以管理员身份动态运行它.
What am doing wrong, is there any other way to install the service that would solve the issue and how to dynamically run it as administrator.
推荐答案
我知道这是旧的,但我一直坚持这个.对我来说,这个特定的问题是通过复制这个文件解决的 - pywintypes36.dll
I know this is old but I was stuck on this forever. For me, this specific problem was solved by copying this file - pywintypes36.dll
来自 ->Python36\Lib\site-packages\pywin32_system32
到->Python36\Lib\site-packages\win32
这篇关于python windows服务“启动服务出错:服务没有及时响应启动或控制请求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!