Home » Automatically restart crashed service

Automatically restart crashed service

by admin
Automatically restart crashed service

When programs, printers or important functions suddenly stop working, it is not uncommon for a terminated service on a Windows server to be the cause. It would be good if the administrator were informed about a crashed service. It would be even better if the service restarted automatically.

DQo8cD48YnIvPg0KPHNjcmlwdCBhc3luYyBzcmM9Imh0dHBzOi8vcGFnZWFkMi5nb29nbGVzeW5kaWNhdGlvbi5jb20vcGFnZWFkL2pzL2Fkc2J5Z29vZ2xlLmpzIj48L3NjcmlwdD4NCjwhLS0gVEVDSEZBUSAtIEltIEFydGlrZWwgLS0+DQo8aW5zIGNsYXNzPSJhZHNieWdvb2dsZSINCiAgICAgc3R5bGU9ImRpc3BsYXk6YmxvY2siDQogICAgIGRhdGEtYWQtY2xpZW50PSJjYS1wdWItOTI5NDg1MzEyMDc1NDI3OSINCiAgICAgZGF0YS1hZC1zbG90PSI1MDc3NjQ3MTY5Ig0KICAgICBkYXRhLWFkLWZvcm1hdD0iYXV0byINCiAgICAgZGF0YS1mdWxsLXdpZHRoLXJlc3BvbnNpdmU9InRydWUiPjwvaW5zPg0KPHNjcmlwdD4NCiAgICAgKGFkc2J5Z29vZ2xlID0gd2luZG93LmFkc2J5Z29vZ2xlIHx8IFtdKS5wdXNoKHt9KTsNCjwvc2NyaXB0Pjxici8+PC9wPg0K

Send email when service crashes

In a recent case I had the problem that the print queue of a Windows print server was terminated at irregular intervals. Since this had an extreme impact on day-to-day business and the cause could not be located immediately, I used a script that informed me by e-mail that the service had crashed. In addition, the script should automatically restart the service so that employees can continue to print.

The script used must therefore check whether the service is started and, if so, restart the service and send an e-mail to one or more recipients.

# Dieses Skript überprüft, ob ein bestimmter Prozess auf dem lokalen Rechner gestartet ist
# Wird der Prozess zum Zeitpunkt der Überprüfung nicht ausgeführt, wird der dazugehörige Dienst  gestartet

$service = "spooler" #Name des Dienstes
$smtpserver = "mail.domain.de"  #E-Mail Server
$sender = "[email protected]"   #Absenderadressen
$recipient = "[email protected]"   #Empfängeradresse
$Subject = "Der Dienst $service wurde auf Server $env:COMPUTERNAME neu gestartet"   #Betreff der versendeten E-Mail

$CheckService = Get-Service -name $service
If($CheckService.Status -ne "running") {
Start-Service $service
Send-MailMessage -SmtpServer $smtpserver -From $sender -To $recipient -Subject $Subject
}

Automatically restart service when finished

The script above checks the status of the service specified in the $service variable. If this is not started, it will be started and an e-mail will be generated. The Powershell script is then integrated into the Windows task scheduler and can run there every minute, for example. This can ensure that the service is restarted in a timely manner once it has been terminated.

Automatically restart a service and be notified by email.

Of course, this does not eliminate the cause. However, under certain circumstances you can gain some time and peace that you need to look for the reasons for the crashes.

See also  Start ups, first drop since 2018: -3.6%. The rush of incentives is slowing down

Also interesting:

This article is like all the others on this site free for you and I hope I could help you. If you want, you can give this blog a little attention in the form of a small donation (PayPal) or via the Amazon Wishlist send.

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy