Jump to content

Sc Stop in a batch file input Redirection not working

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
user777

user777

    Newbie

  • Members
  • Pip
  • 3 posts
Hi i have a batch file ive made to stop some services and then log them to a file
on windows server/xp

start/w/b sc stop CryptSvc
echo CryptSvc >> ServiceSTOP.log
start/w/b sc stop TrKWks
echo TrKWks >> ServiceSTOP.log
start/w/b sc stop MSDTC
echo MSDTC >> ServiceSTOP.log

Thats part of the file, I now want to be able to program another section to load back up the stoped services at a later time. the log worked and says...

Alerter
CryptSvc
TrKWks
MSDTC
svc
ShellHWDetection
SENS
W32Time
SQLWriter

and so on. i want to be able to pass those services back to sc start
i tried
sc start < ServiceSTOP.log
but it does nothing. Id also like to make the "sc stop" section write to the log only if it did indeed stop the service, any help apreciated.

#2
user777

user777

    Newbie

  • Members
  • Pip
  • 3 posts
Wow right i found something that worked

set /p value=<ServiceSTOP.log
echo %value%
sc start %value%
pause

this sent to the command line
sc stop Alerter

Perfect! now does anyone know how i can call diferent lines of a text file ?

Id like to call the second one down in the list CryptSvc from the log file and send that to sc start.
I guess automaticly deleting the first line of the log file would also work, lets find out if thats possible.

If anyones mind works better than me please let me know lol im new to batch files and programming anything.

#3
user777

user777

    Newbie

  • Members
  • Pip
  • 3 posts
Ok i now have a part solution!

echo go!

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (ServiceSTOP.log) do (
set /a N+=1
set v!N!=%%a
)
set serv1=!v1!
set serv2=!v2!
set serv3=!v3!
set serv4=!v4!
set serv5=!v5!
set serv6=!v6!
set serv7=!v7!
set serv8=!v8!
set serv9=!v9!
set serv10=!v10!
set serv11=!v11!
set serv12=!v12!

echo %serv1%
sc start %serv1%
echo %serv2%
sc start %serv2%
echo %serv3%
sc start %serv3%
echo %serv4%
sc start %serv4%
echo %serv5%
sc start %serv5%
echo %serv6%
sc start %serv6%
echo %serv7%
sc start %serv7%
echo %serv8%
sc start %serv8%
echo %serv9%
sc start %serv9%
echo %serv10%
sc start %serv10%
echo %serv11%
sc start %serv11%
echo %serv12%
sc start %serv12%

only problem, id have to repeate thise lines over and over , but thats not a problem as id never need more than 30