topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 1:52 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Small program i could run to restart a stubborn service?  (Read 10993 times)

Grorgy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 821
    • View Profile
    • Donate to Member
Small program i could run to restart a stubborn service?
« on: November 07, 2007, 05:13 PM »
Hi
I'm looking for a little program to restart a service that refuses to do what it is supposed to when i reboot the computer, the service starts but it doesn't actually do what it should till i stop it and restart it  :down:.  At the moment I'm using a couple of bat files to stop it then restart it, this works fine but is beginning to be a bit tiresome, particularly if i forget to do it, so what I am looking for is a program that i could run that would restart a selected service or services and then I could have this set to run at startup.

Does such an animal exist somewhere that anyone knows of?

Thanks
George

Ralf Maximus

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 927
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #1 on: November 07, 2007, 06:01 PM »
Could you not stick the .bat file itself in your startup? 

Of course you want the batch file to wait awhile before doing its thing, so add a TIMEOUT delay to the beginning to hold for x number of seconds, until your system settles down after booting.

If you don't have TIMEOUT.EXE on your system, it can be had as part of the Server 2003 Resource kit.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,069
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #2 on: November 07, 2007, 06:31 PM »
The problem with a single batch file is that it is difficult to establish when the service has stopped so that you can restart it.

If you simply have a batch file that says:

SC STOP service
SC START service

the second command will probably fail if the service doesn't respond quickly to the STOP command.

There doesn't seem to be an easy way to establish when the service has actually stopped short of:

SC QUERY service > textfile.txt

and then use a little program to read the value following the STATE and loop until it is set to the stopped value.

For someone who is quick witted with AutoHotKey programming this would probably be a simple task to do.

Ralf Maximus

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 927
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #3 on: November 07, 2007, 06:36 PM »
Your logic is flawless, your conclusion inescapable.  Normally I would kneel before it's perfection.

However Grorgy says he already has a batch file that works, thus it's reasonable to assume the timing/delay issues have been worked out.

Grorgy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 821
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #4 on: November 07, 2007, 07:04 PM »
ahhh nooo ralf, the timing and delay issues at present are all solved in a purely manual way lol.  I watch the first one, then run the second to restart it  ;D  I have 2 bat files,, first 1 stops it,  i then run the second to restart it, and its the manual bits of all this I'm getting sick of  :)   The way im doing it is easier than going to services and a bit easier than using the FARR plugin but its not ideal (of course ideally the service would start ok but it doesn't)

Ralf Maximus

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 927
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #5 on: November 07, 2007, 07:49 PM »
Ah, then indeed I bow to Ms.Haynes superior wisdom in this matter -- I believe her suggestion for a script strikes closer to a true resolution for you.

Grorgy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 821
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #6 on: November 08, 2007, 02:26 AM »
Well I've used the timeout.exe and have it in my startup folder with both the stop and start and it works ok, so thanks for that Ralf.  Carol's solution would be the ideal way to go, but i can't code to save myself, tho i once wrote a cobol program that said happy xmas and punched it up on those cards that used to exist, but thats all ive ever done lol  So thanks saves me some effort and i learnt a little more,  :)

Cheers
Grorgy

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #7 on: November 08, 2007, 02:48 AM »
A possile solution- don't have the service start automaticially at all. That way you won't have to stop it, just run the start command at a later point in the system startup.

Grorgy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 821
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #8 on: November 08, 2007, 03:16 AM »
Thank you Eoin, makes for a much prettier startup  ;)  and just the one line in the bat file, gets better all the time!

Cheers
Grorgy

Dirhael

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 387
    • View Profile
    • defreitas.no
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #9 on: November 08, 2007, 03:47 AM »
The problem with a single batch file is that it is difficult to establish when the service has stopped so that you can restart it.

If you simply have a batch file that says:

SC STOP service
SC START service

the second command will probably fail if the service doesn't respond quickly to the STOP command.

There doesn't seem to be an easy way to establish when the service has actually stopped short of:

SC QUERY service > textfile.txt

and then use a little program to read the value following the STATE and loop until it is set to the stopped value.

For someone who is quick witted with AutoHotKey programming this would probably be a simple task to do.

True, but using the NET command instead of SC you can get away with something as simple as this:
net stop "name of service" && net start "name of service"

The second part of that line will not execute until the first command is done, no matter how long it takes (you can also write it on separate lines instead, it doesn't matter). The SC command may not wait until the first command is completed before continuing, but NET does :)
Registered nurse by day, hobby programmer by night.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,069
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #10 on: November 08, 2007, 04:16 AM »
Ah - I didn't know you could do that with the net command - useful

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #11 on: November 08, 2007, 04:33 AM »
If you're a coder, you can use StartService and ControlServiceEx. Each blocks until the requested operation times out or is completed.

Ehtyar.

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #12 on: November 09, 2007, 01:15 AM »
... TIMEOUT.EXE on your system, ... can be had as part of the Server 2003 Resource kit.

Were you referring to Timeit.exe , not timeout ??
- I don't see any timeout.exe at the page you linked to.

Grorgy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 821
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #13 on: November 09, 2007, 01:23 AM »
i did a google search for it curt, cant remember the exact place but its easy enough to get, and the one i used was timeout.exe

Ralf Maximus

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 927
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #14 on: November 09, 2007, 10:42 AM »
Indeed, it's not on that page. 

But I swear that's where I got it in the past -- the Server 2003 Resource Kit.  I just checked my server's Windows folder and Timeout.exe is there.  Out of curiosity I checked it's version; definitely part of Server 2003.

Timeout.jpg

Fun fact: The screenshot is 40K, about twice the size of the .exe itself.  :-)

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: Small program i could run to restart a stubborn service?
« Reply #15 on: November 10, 2007, 03:06 AM »
@ Grorgy: Did you try to merely raise the CPU priority of the service in question?
- this methode helped a weakling of mine - but it wasn't a service, though.

--

FunFact2: The image would be 5 KB if saved as GIF.
« Last Edit: November 10, 2007, 03:09 AM by Curt »