Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to restart stopped Service 1

Status
Not open for further replies.

oyazo

MIS
Apr 14, 2008
47
0
0
PT
Hello Friends,

One of my Microsoft Exchnage 2007 services normally stop without any issue.

Can somebody give a script that can restart this service whenever it stops.

Thank you very much.

Oyazo
 
I found the following in one forum,

'Start Service
strServiceName = "Alerter"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next


'Stop Service
strServiceName = "Alerter"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next

----
this site also might help:


cheers
 
Thank you Ladin for the script.

The script

"'Start Service
strServiceName = "Alerter"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next"

did not start the service when the service stopped probably due to my inability to apply it well.

This is HOW I applied it: I copy the "Start Service" part of it and saved as vbs on cdrive on the local system,

I went to services, Right click on the service (alerter), select properties, recovery, first failure, run a program, browse to the program on the local cdrive, apply,ok.

I discover that the service has stopped the following day.

I expected that the script will start the service immediatelly it stops.

Kindly advice probably, I did not apply it well.Note that I only use 'Start Service and not 'stop service.

Thank you so much.


 
oyazo,

why not use the "restart the service" option you can select via the first failure box?

 
I have used it several times but it doesnt work.
 
But if that doesn’t work there is a very big change the script won’t be able to start the service either!

Check the eventlog for errors; it should state the exchange service stopped and it should also state why it could not restart the service. It should be an information type in the system section.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top