DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: How to automatically restart a windows service?  (Read 5,557 times)

Magnatolia

  • Participant
  • Joined in 2016
  • *
  • Posts: 4
How to automatically restart a windows service?
« on: September 22, 2017, 02:01 PM »
Hi guys,

Is it possible to use FARR to automatically restart the windows audio service? I'm having a problem where I have to restart the service after every 1 or 2 audio files and want to try and automate this a bit more.

Thanks!

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: How to automatically restart a windows service?
« Reply #1 on: September 22, 2017, 08:36 PM »
First thing would be to find out how to make a batch file to restart the service, then you can easily invoke that batch file from FARR.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: How to automatically restart a windows service?
« Reply #2 on: September 23, 2017, 01:45 AM »
Wouldn't it be better to discover why it's necessary to restart the service?

ie.
Is the program playing the files causing the service to screw up?
Try another program.

Is it a hardware or driver fault?
Check the Eventlog.

When the service screws up is it because it has stopped or it is running but still needs a restart?

Really need more info, it's easy to do a small PowerShell script to restart the service if its stopped but where it's still shown as running is probably going to be a little trickier since how would you know if it's being used or not?

EDIT: Can also restart the audio service using a command file, eg.

Code
sc stop Audiosrv
ping 127.0.0.1 -n 10 >NUL
sc start Audiosrv

No checks, waits 10 seconds after stopping (ping command 10 times), then starts it.
Could add check for status with sc query Audiosrv but I think it'd be better to find out why it's necessary in the first place.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: September 23, 2017, 04:24 AM by 4wd »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: How to automatically restart a windows service?
« Reply #3 on: September 23, 2017, 08:11 AM »
When the service screws up is it because it has stopped
If that's the case, then my NANY 2013 entry KeepUpApp as featured here, could be of interest to you. It won't work if the service isn't responding for any reason though.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Original address: https://www.donationcoder.com/forum/index.php?topic=44384.0