无法更改服务启动模式

问题描述 投票:0回答:1

我正在自动部署一个应用程序。

在通过Choco安装并启动服务后,我试图将服务启动模式(StartMode)改为自动(Auto),但我得到的是21作为returnvalue,因此模式没有改变。

PS C:\Windows\system32> $appservice = Get-WmiObject -Class Win32_Service -Filter "Name='<app_name>'"
PS C:\Windows\system32> $appservice.ChangeStartMode("Auto")


__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 21
PSComputerName   :
PS C:\Windows\system32> Get-WmiObject -Class Win32_Service -Filter "Name='<app_name>'"


ExitCode  : 0
Name      : <app_name>
ProcessId : 3180
StartMode : Manual
State     : Running
Status    : OK

恳请帮助!TIA

windows powershell wmi get-wmiobject
1个回答
0
投票

试试

Get-Service -Name 'TheServiceName' | Set-Service –StartupType Automatic
© www.soinside.com 2019 - 2024. All rights reserved.