0

I have around 140 virtual servers that need regular maintance, they all run message queuing, but the storage file needs to be kept below 512MB. I need to stop all the services in order and the last being MSMQ service, then go to the system32\msmg\storage file and delete all the *.mq files, once done I then would like the batch file to restart the services with the first being msmq. I also need to add some error messages, so if the service can not stop or start or its already running etc, below is what I think it should be like but not sure,. may be there is a better way of doing it, the plan would be to but the batch file on all the servers and set a sceduled task to Run the batch file. Would it be possible to have an email generated to say that it has been completed successfully ?

NET STOP AVLDataService 2>&1|FIND "2182" 
IF errorlevel 1 goto :sub_already_stoped
jeremy
  • 9,455
  • 4
  • 36
  • 57
Phil
  • 1
  • 1

2 Answers2

0

Try this:

@echo off
title Service Uninstaller
color 0A

set blank=
set service=blank

:start
echo.
echo.
echo.
SET /P service=Enter the name of the service you want to uninstall:  

IF "%service%"=="" (ECHO Nothing is entered
GoTo :start)

cls
echo.
echo.
echo.
echo We will delete the service: %service%

ping -n 5 -w 1 127.0.0.1>nul

::net stop %service%
ping -n 2 -w 1 127.0.0.1>nul

sc delete %service%
pause

:end
Tisho
  • 7,474
  • 5
  • 40
  • 52
Chris
  • 1
0

You are on the right track. A batch file can certainly accomplish this with NET START/STOP calls in the desired order. For error handling, if the error is non-fatal echo a message to a text file and continue. If it's fatal, then use goto to jump to the end of the file. At the end of the file, you can email yourself the text file with error messages using BMAIL.

Vik David
  • 3,154
  • 3
  • 19
  • 26
  • thanks for the reply, would it be better to have two batch files one for the net stop and the deletion of the *.mq files then a second batch file to net start ? at the bottom of the first batch file I would need to add some sort of pause to give it time to delete the *.mq files before starting the msmq service. – Phil May 27 '11 at 09:18
  • Since one's dependent on the other, keep them as one. You can pause using `ping` or `timeout` [See here](http://stackoverflow.com/questions/1672338/how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos). – Vik David May 27 '11 at 13:29
  • I dont quite know what is going wrong with my batch file, C:\Temp>NET STOP Message Queuing 2>&1 | FIND "2182" IF errorlevel 1 goto :sub_ already_stopped File not found - IF File not found - ERRORLEVEL File not found - 1 File not found - GOTO File not found - :SUB_ALREADY_STOPPED C:\Temp>ping 1.1.1.1 -n 20 1000 1>NUL I'm trying to stop the message queuing, but then I want to delete files in the msmq\storage folder the *.mq files like this del c:\windows\system32\msmq\Storage\*.mq /s it comes back with files in use which indiactes that the msmq is still running, any help – Phil Jun 09 '11 at 19:23