How to check if a service is running and stop a shutdown via a script

trevsoft
trevsoft used Ask the Experts™
on
Hi Experts,

Im having a bit of an issue with both my servers. One is running SBS 2003 and the other is running server 2008 standard.

Both are running StorageCraft ShadowProtect backup software.  We are also backing up our servers off-site into a backup data centre.

The problem i am having, is when there is a windows update, or a power outage the server reboots or shuts down.

With ShadowProtect, if the backup job is not completed successfully or aborted from the console. It causes the system to do its next backup via VDIFF. This is my problem, when this happens the back goes from taking seconds or minutes, to days.

What i am looking for is a script that will allow me to check and see if the state of the shadowprotect backup is in the process of running and if so, execute an abort so once it is aborted the server can continue to shutdown as it normally would.

Like this once the server comes back online, it wont know any difference and just send the next increment over to the data centre.

I know this solution may be made of a few different solutions, but everyone who helps, thank you in advance.



Trevor
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2011

Commented:
in a  simple batch script....

Depending on how your abort sequence is, or if you just need to kill the process....
tasklist | fin /i "yourservice.exe" && taskkill /f /im yourservice.exe

tasklist | fin /i "yourservice.exe" && start "" abortsequence.exe /switches

Open in new window

Commented:
Hi John,

I will have to give that one a go, but im not sure if it will do the job.

I know shadowprotect runs as a service, so im guessing there must be a call we can do to make the service abort the backup.

I think killing the service is as bad as the server loosing power.


Trevor
Most Valuable Expert 2011
Top Expert 2011

Commented:
Thats why I was hoping for more info, on the secondary command. If the service executable has the proper abort switches, that would be the safe way to go.  

And this would be better for a service ...

And the "fin" above should be "find"
tasklist | find /i "yourservice.exe" && net stop "yourservice"

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

You can use the following vb script.
On Error Resume Next
Dim strServiceName
Dim strMachineList
strServiceName = "REPLACE_WITH_SERVICE_NAME" 'Service name should be in quotes
strComputer = "." 'use . for local computer else provide a computer name

Dim objWMI : Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMI.ExecQuery("Select * from Win32_Service where Name = '" & strServiceName & "'")

For Each objService In colServiceList
	If objService.State <> "Stopped" Then
		objService.StopService()
		WScript.Sleep 5000	
	Else
		Wscript.Quit
	End If	
Next

Open in new window

Top Expert 2007

Commented:
As was mentioned, i do not think that shutting down the service is going to help. What you probably need is an API call to shadowprotect backup program to check status and abort gracefully, or alternatively to set the state condition to what you want ( Do an incremental, not a VDIFF on next backup )
You may need to check their site to get info on their API or get an SDK if they have one.

I hope this helps !

Author

Commented:
great work.

Author

Commented:
np

Author

Commented:
np

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial