Please help me create a batch file which creates txt files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
johnmilton007
Posts: 1
Joined: 24 Jan 2015 09:47

Please help me create a batch file which creates txt files

#1 Post by johnmilton007 » 24 Jan 2015 10:05

Hi,

I am trying to create a batch file that would help me to create the txt file along with the status of the service in a server.
below command provides the status: "running/not running" inside the "servername.txt" file. But I am looking out for a batch file command that would create the txt file with status in its file naming convention. Example: "servername running/notrunning.txt"

NET USE \\servername\IPC$ /USER:Miltonjo_aps password
sc \\servername query "service name" | find "STATE" > servername.txt

Appreciate you guidance..

Regards,
John

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Please help me create a batch file which creates txt fil

#2 Post by Squashman » 24 Jan 2015 16:38

Code: Select all

@echo off
NET USE \\servername\IPC$ /USER:Miltonjo_aps password
FOR /F "tokens=4" %%G in ('sc \\servername query "service name" ^| find "STATE"') DO set state=%%G
echo %state%>Servername_%state%.txt

Post Reply