0

I am automating an application deployment.

After installing and starting the service via Choco, I am trying to change the Service StartMode to Auto, but I am getting 21 as the returnvalue and hence the mode is not changed.

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

Kindly help. TIA

sriramsm04
  • 343
  • 1
  • 7
  • 22
  • 2
    `Get-Service -Name 'TheServiceName' | Set-Service –StartupType Automatic` ought to to it.. – Theo May 11 '20 at 11:06

1 Answers1

0

Try

Get-Service -Name 'TheServiceName' | Set-Service –StartupType Automatic
Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
sriramsm04
  • 343
  • 1
  • 7
  • 22