?
Solved

Remotely stop Services on W2k servers from W2k3 server

Posted on 2005-03-17
8
Medium Priority
?
3,191 Views
Last Modified: 2013-12-01
I'm trying to get my Veritas Backup Exec jobs to complete with out errors.  It keeps choking on some files used by DHCP and WINS, each running on a different server on my network.  I want to create a .bat job that will stop the services, run the backup, then restart them.  I tried using netsvc and sc.  SC will allow me to get information on the services, but netsvc will not work from the W2k3 server.  It says that "'netsvc' is not recognized as an internal or external command, operable program or batch file."  Is there a similar command for W2k3?  This would have been perfect....if it worked.
0
Comment
Question by:fhieber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 25

Expert Comment

by:mikeleebrla
ID: 13567144
try net stop servicename
then net start servicename to restart it again
0
 
LVL 1

Author Comment

by:fhieber
ID: 13567186
That won't work on a remote server.  I have 3 servers, server1,2,3.  Server3 is doing the backup jobs.  I want it to run a batch file that will stop and start the DHCP service on server1 and the WINS service on Server2.  If they were both running on Server3 "net stop servername" would work fine.
0
 
LVL 15

Expert Comment

by:veedar
ID: 13567538
Try psexec or psservice from the pstools suite. They are free and great for remote execution.

http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
LVL 25

Expert Comment

by:mikeleebrla
ID: 13567566
sure it will,,, just run the bat locally,,ie on the remote server.  you can do it as a scheduled task if youd like.  simply put the bat file on the server and schedule a time to run it.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13568876
You were on the right track with sc. "sc \\RemoteMachine stop SomeService" will stop a service on a remote machine. It will return immediately, though, so for a proper solution, you have to query the status and check if everything went okay.
Here's a little batch that will do that.
Give it the command "start" or "stop" as first argument, the machine name (with leading backslashes) as second, and any services to be stopped/started as additional arguments.
Examples:
services.cmd stop \\Server1 DHCP WINS
services.cmd stop \\Server2 WINS
services.cmd start \\Server1 WINS DHCP
services.cmd stop \\Server2 WINS
It will return errorlevel 0 if everything went okay, otherwise equal to the number of services that couldn't be stopped/started.

The script requires sleep.exe from the Resource Kit:
Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

====8<----[Services.cmd]----
@echo off
setlocal
:: *** Timeout in seconds
set TimeOut=30
set Error=0
if "%~3"=="" goto :eof

set Command=%~1
shift
set Machine=%~1
shift

:loopServices
if "%~1"=="" goto leave
set Service=%~1
shift
call :%Command%
goto loopServices

:: **********************************************************************
:stop
echo Trying to stop %Service% on %Machine% ...
sc %Machine% query "%Service%" | find /i "stopped" && goto :eof
sc %Machine% stop "%Service%"
set Count=0
:loopStop
sleep 5
set /a Count+=5
sc %Machine% query "%Service%" | find /i "stopped" && goto :eof
if %Count% GTR %TimeOut% (
  set /a Error+=1
  echo Timeout: Couldn't stop %Service% on %Machine%.
  goto :eof
)
goto :loopStop
:: **********************************************************************

:: **********************************************************************
:start
echo Trying to start %Service% on %Machine% ...
sc %Machine% query "%Service%" | find /i "running" && goto :eof
sc %Machine% start "%Service%"
set Count=0
:loopStart
sleep 5
set /a Count+=5
sc %Machine% query "%Service%" | find /i "running" && goto :eof
if %Count% GTR %TimeOut% (
  set /a Error+=1
  echo Timeout: Couldn't start %Service% on %Machine%.
  goto :eof
)
goto :loopStart
:: **********************************************************************

:leave
exit /b %Error%
====8<----[Services.cmd]----
0
 
LVL 13

Accepted Solution

by:
gpriceee earned 1000 total points
ID: 13571435
In Backup Exec under Job Setup, edit the job and go to Settings --> Pre/Post Commands.
Enter the path and filename of a pre-command.  For example, C:\BEscripts\pre.bat
Create a script that will stop the services: NET STOP "DHCP SERVER"
Use the quotes if the services have spaces

Under Settings --> Pre/Post Commands, enter the path and filename of a post-command.  For example, C:\BEscripts\post.bat
Create a script that will start the services: NET START "DHCP SERVER"
Use the quotes if the services have spaces

On each server that you want a pre and post command to run, create the directory and place the script in it; the scrit content does not have to match, so you can be flexible; however, the paths and names must be exact.

If you do it this way, timing is no longer an issue because nothing will stop or start until Backup Exec tells it to.
REMEMBER: examine the options available once you select pre/post commands.  If you don't need a command on a server, you can leave off the file, but if you select "Run job only if pre-command is successful," you won't be happy.
0
 
LVL 1

Author Comment

by:fhieber
ID: 13575903
Are you saying that the Backup Exec and/or Remote Agent will call .bat files on all three servers, all will have the same name and path, but the contents will be different depending on what I'm trying to start or stop?   I knew I could do that on the machine with Backup Exec installed.  How does it know to do the same thing on the other servers? Is it the Remote Agent that is doing it?
0
 
LVL 1

Author Comment

by:fhieber
ID: 13583717
Such a simple solution.  I looked all over for this!  Thanks.  I didn't realize that the pre and post jobs would run on all of the servers that are backed up.  Very cool.  I still need to tweak my Bat files, but it looks like it ran on all three servers last night.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
This program is used to assist in finding and resolving common problems with wireless connections.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question