【问题标题】:Windows command line access denied to install service, and I'm the administratorWindows 命令行访问被拒绝安装服务,我是管理员
【发布时间】: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


【解决方案1】:

解决方案涉及以管理员身份运行命令行。这是通过右键单击命令提示符并选择以管理员身份运行命令行来执行的。

在 Windows 中,登录计算机的用户可能是 Windows 管理员,但权限不会自动扩展到命令行。具有管理员权限的用户必须选择以管理员身份运行命令行才能执行保留给管理员的命令,例如执行 Windows 服务的安装。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    相关资源
    最近更新 更多