Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Restart Windows Service



  • Please log in to reply
6 replies to this topic
Hello2215
  • Members
  • 106 posts
  • Last active: Oct 07 2016 11:42 AM
  • Joined: 16 Oct 2012

Hey,

 

I am wondering if it is possible to make a script that stops a designated service then starts it again once it has stopped.

 

I have searched a few other forum topics and the content has gone over my head :(

 

If anyone could help me that would be greatly appreciated, the script needs to search for the service if it exists stop and start it and if it doesn't display a Msgbox or error message of some sort.

 

Thanks,

Hello2215 :)



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013
✓  Best Answer

Use the CMD's sc command.

RunWait,sc stop "AdobeARMservice" ;Stop AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
MsgBox %Errorlevel%
RunWait,sc start "AdobeARMservice" ;Start AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
return


Hello2215
  • Members
  • 106 posts
  • Last active: Oct 07 2016 11:42 AM
  • Joined: 16 Oct 2012

 

Use the CMD's sc command.

RunWait,sc stop "AdobeARMservice" ;Stop AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
MsgBox %Errorlevel%
RunWait,sc start "AdobeARMservice" ;Start AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
return

Thanks for the help :)



JonnyHotkeys
  • Members
  • 16 posts
  • Last active: Feb 08 2017 08:06 PM
  • Joined: 08 Oct 2013

Hi there, thanks for the example. Excellent stuff!

 

total noob, with several services that I'd like to manually manage (start when they're needed, as they struggle to start by themselves, failing to honour the ONDEMAND setting).

 

I have Sandboxie, to run apps in a virtual container in virtual memory.

 

I don't need it running all the time, but if it's only on manual and I use the context menu option to run an application sandboxed, it fails. Toggling the service status would be a good (interim?!) solution...

 

So I've followed some examples, but not sure if there are better ways to do things.. also not even working yet. Here's the code (I've modified and combined working code that uses same commands etc, alas no avail.

 

#g::StopRestart("SbieSvc")
StopRestart(svc)
{
RunAsAdmin() ; installed superuseful script that runs scripts as admin. a necessity I think for handling process/service requests?
Process, Exist, "C:\Program Files\Sandboxie\SbieSvc.exe" ; check to see if program is running
If (ErrorLevel = 0) ; If program is not running -> Run
  {
  ;RunWait,sc start %svc%;Start svc
  RunWait, sc start sbiesvc
  }
Else
  {
    RunWait,sc stop %svc%; Stop service.
    If (ErrorLevel = 0) ;If svc stopped
     {
       MsgBox Success!
      }
 } 
}
 


zzzTAG
  • Members
  • 15 posts
  • Last active: Apr 01 2014 08:16 AM
  • Joined: 22 Jun 2006

Hopefully it is ok to bump this one. What would have to be changed to make this script restart (stop, wait, start) a service every 90 minutes?



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013
#Persistent
SetTimer, StartService, % 90*60*1000 ; In Milliseconds.
return

StartService:
RunWait,sc start "AdobeARMservice" ;Start AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
return


zzzTAG
  • Members
  • 15 posts
  • Last active: Apr 01 2014 08:16 AM
  • Joined: 22 Jun 2006
#Persistent
SetTimer, StartService, % 90*60*1000 ; In Milliseconds.
return

StartService:
RunWait,sc start "AdobeARMservice" ;Start AdobeARM service.
If (ErrorLevel = 0){
	MsgBox Success!
}
return

Thanks! Just had to change "start" to stop, and the service automatically restarted when stopped. Also removed the messagebox, but the script works just as intended.