Re: Batch script for maintaing remote services

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"test" <harpreet.noni@xxxxxxxxx> wrote in message
news:119981da-8a45-4516-931a-868aa24995bc@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Feb 21, 2:44 pm, "Pegasus \(MVP\)" <I....@xxxxxxxxxx> wrote:
*** See below.

"test" <harpreet.n...@xxxxxxxxx> wrote in message

news:271710da-2e40-4b73-9e9f-3af42a2ba803@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks again Pegasus. I am now using your suggestion and not including
"EnableDelayedExpansion" statement. Its working as expected. I tried
the above code but got following error:

C:\Documents and Settings\dir1\dir2\TempVBS.VBS(15, 2) CDO.Message.1:
The
"SendUsing" configuration value is invalid.

I tried searching on this error but could not find on what value I
should change "sendusing" value to. Can you please advise.
*** Sorry, I cannot comment unless you post the version of
*** the code you actually use.

Also, as far as killing of services is concerned, I was able to come
up with following code. Just wanted to have your suggestion this.:

Each service is stopped and a delay is given after which the service's
status is checked. If service is still found in "stop_pending" (this
is status the job gets in after going to STOPPING status) status, I am
using taskkill command to kill the service. Does this look ok?

@echo off
REM service_names.txt contains all service names
REM This code is for starting services one after other

FOR /F %%i IN (service_names.txt) DO (

sc \\servername stop %%i

ping localhost -n 10 > nul

sc \\servername query %%i | find /i "stop_pending" || taskkill /s
computername /u userid /p password /im %%i
)

*** You have the right idea but you're testing for the wrong
*** thing. Since you want to check if the service has stopped,
*** the code should look like so:
sc \\servername query %%i | find /i "stopped" || taskkill /s computername
/u
userid /p password /im %%i

However, there is fundamental issue here. "%%i" is the name of the SERVICE
you wish to stop. Taskkill.exe will kill a TASK, not a SERVICE. What are
you
trying to achieve with the taskkill command?

Pegasus, below is the code I have used when trying to implement mail
functionality

@echo off

cd "C:\Documents and Settings\dir1\Desktop"

set sender=harpreet.wa@xxxxxxx
set receiver=harpreet.wa@xxxxxxx

REM the server value was fetched using nslookup command

set server=name.abc.com
set subject=Test Mail
set body=The quick brown fox

set schema=http://schemas.microsoft.com/cdo/configuration/
REM set scr=TempVBS.VBS
set scr=TempVBS.VBS
echo> %scr% Set objEmail = CreateObject("CDO.Message")
echo>>%scr% With objEmail
echo>>%scr% .From = "%sender%"
echo>>%scr% .To = "%receiver%"
echo>>%scr% .Subject = "%subject%"
echo>>%scr% .Textbody = "%body%"
echo>>%scr% With .Configuration.Fields
echo>>%scr% .Item ("%schema%" ^& "sendusing") = 1
echo>>%scr% .Item ("%schema%" ^& "smtpserver") = "%server%"
echo>>%scr% .Item ("%schema%" ^& "smtpserverport") = 25
echo>>%scr% .Item ("%schema%" ^& "smtpauthenticate") = cdoBasic
echo>>%scr% .Item ("%schema%" ^& "sendusername") = "%sender%"
echo>>%scr% End With
echo>>%scr% .Configuration.Fields.Update
echo>>%scr% .Send
echo>>%scr% End With
cscript //nologo %scr%
del %scr%

pause

Pegasus, actually when I bring a service down using sc command, some
services on the
"My Computer->Manage->Services and applications"
shows as STOPPING. On querying their status using sc command, I found
that at this time their status was "stop_pending". So shouldnt I be
using "stop_pending" to kill these services instead of "stopped" as I
only want to kill those services that are stuck in STOPPING status and
not STOPPED?

Thanks for ponting. It seems taskkill is not the option I want to use
as I want to kill a SERVICE. I tried pskill but it seems it is not
installed. and I even have a restriction of not installing else. Any
other way?

TIA
=====================
I tested your script on my machine after adjusting the various names to my
own environment and after changing the line
echo>>%scr% .Item ("%schema%" ^& "sendusing") = 1
back to
echo>>%scr% .Item ("%schema%" ^& "sendusing") = 2
It worked perfectly.

You can look up your SMTP mail server with nslookup but there are some
further requirements to be considered:
- Does this server listen on port 25?
- Does it require user authentication?
A much easier way to get the server name and its prerequisites is to look
them up in your mail client (Outlook, Outlook Express). It's all there for
you to see!

If a service is stuck in the stop_pending state then there is nothing you
can do about it other than restarting the machine. AFAIK there is no command
to zap such a service. Ask the supplier of the service for further advice.
There might be a task that you need to shut down before you can kill the
service.


.



Relevant Pages

  • Re: Batch script for maintaing remote services
    ... Thanks again Pegasus. ... using taskkill command to kill the service. ... REM This code is for starting services one after other ... Taskkill.exe will kill a TASK, ...
    (microsoft.public.windowsxp.general)
  • Re: Batch script for maintaing remote services
    ... Thanks again Pegasus. ... using taskkill command to kill the service. ... Taskkill.exe will kill a TASK, ... You can look up your SMTP mail server with nslookup but there are some ...
    (microsoft.public.windowsxp.general)
  • Re: MySQL FC3
    ... >> After you get your mysql back up and running, ... > same user that the mysqld server runs as. ... > You can stop the MySQL server by sending a normal kill (not kill ... > cat command; these cause the output of cat to be substituted into the ...
    (Fedora)
  • Re: .Net Server and taskkill
    ... >The latest versions of Microsoft's Server OSes .NET come with a command ... >create a program to just keep feeding taskkill commands to the server until ... There are plenty of 'kill app' programs written already for Windows, ...
    (Focus-Microsoft)
  • Re: Start process with batch file - want to close DOS console
    ... It starts an X server and basically runs in the background. ... is a DOS console opens up and stays there until I manually close it. ... for the DOS console to execute the command then go away. ... Thank you Pegasus. ...
    (microsoft.public.windowsxp.general)