Link to home
Start Free TrialLog in
Avatar of rutgermons
rutgermons

asked on

batch to shutdown windows services

Folks

How can I create a batch that can logon to 2 or 3 different servers which invoke a command to shutdown 5 windows servers on each server ? in addition, I would like to specify the stop order in the batch but also ensure between stopping each service that there is a 60 second wait period between stopping the next

all help will do
Avatar of Chris Millard
Chris Millard
Flag of United Kingdom of Great Britain and Northern Ireland image

I would use the free PSEXEC command (part of PSTools) to remotely execute the commands:-

http://technet.microsoft.com/en-gb/sysinternals/bb897553.aspx

PsExec can be used to run any commands on remote servers. The only thing you might have issue with is the waiting 60 seconds. Although I believe the Windows 2003 resource kit (again a free download) has a sleep.exe command that can be used to pause a script:-

http://www.microsoft.com/en-gb/download/details.aspx?id=17657

OR this free alternative-

http://www.sleepcmd.com/
SOLUTION
Avatar of Brett Danney
Brett Danney
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, all the above is good, but you will also have to add the option to psexec to accept the eula if you run it within a batch file and point it to other servers.  Just start the command for psexec this way:

psexec /accepteula

Open in new window

 

and add the addtional commands and options as needed.

example using other expert's excellent post:

psexec /accepteula @C:\Scripts\Servers.txt -c c:\Scripts\StopServices.cmd -v -s -d

Open in new window


Good Luck,
- gurutc
You only have to accept the EULA once on the machine running psexec, so that isn't a big issue, but yes, it is a good idea to always add that switch.
We've seen it happen when pointing to other servers.  psexec actually temporarily installs itself on the remote system as a service and then executes the remote commands.  Since the remote system's never run psexec it fails silently because of the eula.

It's one of those 'sometimes it works, sometimes it don't' things.

- gurutc