How to show details of service

Stellantisc2022 26 Reputation points
2022-07-07T01:07:14.097+00:00

Hello

How to show the details of windows services on the Windows server 2019 standard core by commands?
I tried to use it:

Get-Service -Name xxx |Format-List *

But, It was not enough for me.

In fact, a service on my server keep stopping automatically, I had to start it manually every time, I want to configure it to restart automatically when it stops.

Q1: Which commads are used for show the service's parameters of automatic restart after failure?
Q2: How do I configure it to start aumomatically when it fails or stops?

Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} vote

Accepted answer
  1. Sam Erde 151 Reputation points MVP
    2022-07-07T20:38:37.697+00:00

    You can use the sc command-line tool to query a service and configure it to restart automatically when it fails.

    Query a service's failure configuration using 'sc qfailure':
    sc qfailure <ServiceName>

    Specify that recovery actions will be triggered when a service stops as the result of an error using 'sc failureflag':
    sc failureflag <ServiceName> flag=1

    Set one or more recovery actions after a failure using 'sc failure':
    sc failure <ServiceName> [reset= <ErrorFreePeriod>] [reboot= <BroadcastMessage>] [command= <CommandLine>] [actions= {"" | {[run/<MS>] | [restart/<MS>] | [reboot/<MS>]}[/...]]

    Here are some examples that I borrowed from Microsoft Learn:

    sc failure msftpsvc reset= 30 actions= restart/5000  
    sc failure dfs reset= 60 command= c:\windows\services\restart_dfs.exe actions= run/5000  
    sc failure dfs reset= 60 actions= reboot/30000  
    sc failure dfs reset= 60 reboot= "The Distributed File System service has failed. Because of this, the computer will reboot in 30 seconds."  actions= reboot/30000  
    sc failure myservice reset= 3600 reboot= "MyService crashed -- rebooting machine" command= "%windir%\MyServiceRecovery.exe" actions= restart/5000/run/10000/reboot/60000  
    

    The full documentation for sc failure is in the "previous versions" area of Microsoft Learn at this link.


2 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-07-07T01:19:43.403+00:00

    Read on here.
    https://learn.microsoft.com/en-us/archive/blogs/jcalev/some-tricks-with-service-restart-logic

    the better more bullet proof option may be a scheduled task that runs a script to check if the service is starting or running and if not start it.

    --please don't forget to upvote and Accept as answer if the reply is helpful--


  2. Anonymous
    2022-07-07T02:20:07.15+00:00

    You can use schtasks.
    https://learn.microsoft.com/en-us/windows/win32/taskschd/schtasks

    and some ideas for a script here.
    https://stackoverflow.com/questions/21074223/how-to-check-service-state-using-vbscript

    --please don't forget to upvote and Accept as answer if the reply is helpful--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.