【发布时间】:2014-11-28 07:03:40
【问题描述】:
我正在尝试使用 Python (3.4) 安装 Windows 服务。安装后我打算运行它。除了演示在 Windows 中运行的服务之外,它不执行任何功能。
我在安装服务时获得以下访问权限:
我是计算机的管理员,因此我应该有权执行此操作。
可能是因为命令行正在尝试使用 Python 安装服务。 Python 是否有权通过命令行执行此操作?
我怎样才能解决这个问题。是否有需要更改权限的特定文件?
我已包含服务中的代码以防万一。
感谢您的帮助。
#Run a Windows Service
import win32serviceutil
import win32service
import win32event
import os
import sys
import time
from threading import Thread
import http.server
class ServiceLauncher(win32serviceutil.ServiceFramework):
_svc_name_ = "PythonService"
_svc_display_name_ = "Python based win32 service"
_svc_description_ = ""
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
thread = Thread(target = httpserver.run_httpserver)
thread.daemon = True
thread.start()
while (1):
rc = win32event.WaitForSingleObject(self.hWaitStop, 1000)
if rc==win32event.WAIT_OBJECT_0:
# Stop event
break
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(ServiceLauncher)
【问题讨论】:
-
用户帐户控制 (UAC) 可能会妨碍您:您是否以管理权限显式启动命令行? (如果是这样,它应该在命令行窗口的标题栏中的某处显示“管理员”。)
-
您可能不是管理员。您可能是使用 UAC 拆分令牌的标准用户。
标签: windows winapi python-3.x