无法在计算机“."上启动服务 [英] Cannot start service on computer '.'

查看:159
本文介绍了无法在计算机“."上启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell 创建和启动 Windows 服务.

I'm trying to create and start a windows service using PowerShell.

当我使用除一个特定名称之外的多个名称时,服务已创建但无法启动.

The service is created but cannot be started when I use various names besides one particular name.

当我使用 exe 文件的名称创建服务时,它可以启动,但是当我给它一个不同的名称时,它无法启动.

When I create the service with the name of the exe file it can be started but when I give it a different name it fails to start.

我以管理员身份运行 PowerShell 脚本.

I'm running the PowerShell script as administrator.

有什么建议吗?

function InstallService(
    [string] $MsDeployHost,
    [string] $ServiceName,
    [string] $DisplayName,
    [string] $ServicePath,
    [string] $ServiceDescription,
    [object] $Credential) {
    if($MsDeployHost -eq "local") {        
        New-Service -name $ServiceName -binaryPathName $ServicePath -displayName $ServiceName -StartupType Automatic
        Start-Service -name $ServiceName
    } else { ....  

我得到的错误:启动服务:服务'Service1(Service1)' 由于以下错误而无法启动:无法在计算机."上启动服务 Service1.

The Error I get: Start-Service : Service 'Service1 (Service1)' cannot be started due to the following error: Cannot start service Service1 on computer '.'.

当我尝试手动启动它时,我得到:错误 1053:服务没有及时响应启动或控制请求"

When I try to start it manually I get: "Error 1053: The service did not respond to the start or control request in a timely fashion"

推荐答案

问题在于,除非您的服务是编写来处理它的,否则您需要使用特定的服务名称才能运行特定服务(并注意名称区分大小写).这是因为服务在启动时需要向服务控制管理器注册,以使用其服务名称接收启动/停止通知并发送状态更新.如果您使用不同的名称安装服务,但可执行文件无法知道这一点(通过配置设置或诸如此类),则此注册将失败并且服务无法启动(对于操作系统来说,它看起来好像服务无法响应).

The problem is that, unless your service is written to handle it, you need to use a particular service name in order to run a particular service (and note that the name is case-sensitive). This is because the service, on startup, needs to register with the Service Control Manager to receive start/stop notifications and send status updates, using its service name. If you install the service with a different name, but the executable has no way of knowing this (through a configuration setting or whatnot), this registration will fail and the service can't start (to the operating system, it will look as if the service is failing to respond).

您可以将显示名称设置为您喜欢的任何名称,但您不能使用任意服务名称,除非该服务旨在支持这一点.

You can set the display name to whatever you like, but you cannot use an arbitrary service name unless the service is designed to support this.

这篇关于无法在计算机“."上启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆