Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Remotely stop Services on W2k servers from W2k3 server

Posted on 2005-03-17
8
Medium Priority
?
3,192 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 86

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

580 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