topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Monday December 9, 2024, 1:09 am
  • 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: Quick script to change the recovery options of a Windows Service  (Read 11471 times)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Need to change the recovery options on a windows service (for an added software) from the default "take no action" to "restart service" on at least "first and second occurrence" and probably on "all subsequent" as well.
The timing is not critical as the defaults from the GUI when used in control panel work fine but this is for some people who are not here and should not be allowed to even know that control panel exists.  :)
I almost got there with SC stated as :
          "sc failure xxxxx actions=restart/60000/restart/60000// reset=120" but not quite. Windows error-ed "invalid option" but it should work with xxxxx being the service name.

This format also may not set the subsequent failure option to restart as well which is the layout I have tested and found to work best.  I am not familiar with using SC and have never configured anything with it before.  I also saw some other more complex comands but I only need to set these three options on only this one service.
Thanks

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Don't know that I ever actually tried that, but give this a read: http://technet.micro...ibrary/cc742019.aspx It appears that the space locations are critical and I think the actions set has to be enclosed in {}.

x16wda

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
don't you need spaces between the = chars and the parameter? (like "reset= 120")?  i seem to remember that.
vi vi vi - editor of the beast

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
As an example, the following worked fine for me, (Win8Pro x86):

sc failure browser actions=restart/60000/restart/60000/restart/60000 reset=86400

First, Second, and Subsequent actions Restart after 60 seconds, failure counter reset after 1 day for service Computer Browser (service name = browser).

Naturally, you need admin privileges.
« Last Edit: July 01, 2014, 11:20 AM by 4wd »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
I was thinking like x16wda that the space was necessary also ... But that's probably just because the documentation on SC.exe says it is a requirement.. *Shrug* :D

But...
As an example, the following worked fine for me, (Win8Pro x86):

sc failure browser actions=restart/60000/restart/60000/restart/60000 reset=86400

First, Second, and Subsequent actions Restart after 60 seconds, failure counter reset after 1 day for service Computer Browser (service name = browser).

I can confirm this spaceless version worked for me on Windows 8.1 Pro.

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
4Wd hit the nail on the head.  (As usual 4WD always hits something :)  )

Anyways, thanks for the replies.  I had somebody point out the importance of spaces "Always after = never before" or some such.  Truly it is.
The part about the admin was driving me nuts trying to figure out how to give admin priv to a bat file until I hit my OWN head and remembered "DUH"
Right Click > Run as Admin.  Works every time (or for this it did anyway)
Thanks to all for the input
Not to be wasting time or space but I got another good question but I'll close this and post it separate.


questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
SJ, I don't know how you made it work.   On every instance of the = it followed the rtule staed in first reply.  the = had to have a space afterward.  Also using 8.1 so I don't know what the difference is.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
SJ, I don't know how you made it work.   On every instance of the = it followed the rtule staed in first reply.  the = had to have a space afterward.  Also using 8.1 so I don't know what the difference is.

Hm... That is weird. I just pasted 4wd's string into an admin CP, changed the target service to fax (as it's unused and breakable), hit enter and checked the results. I was actually expecting it to fail...but it worked just fine. *Shrug* I don't know..