Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Help with cmd prompt


  • Please log in to reply
3 replies to this topic

#1 heltune

heltune

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:04:17 PM

Posted 23 April 2013 - 11:56 AM

im using sc.exe query state= all

it lists all the services windows xp have, whether stopped or running

here's my problem, how can i separate those services that are stopped <state: 1 stopped>

and create a text file as output where all stopped services willl be listed there

what is the proper syntax for that

shall i use the IF <how> and FIND command to list all servies that are not running that is "find "display_name" or "service_mame" as an output to the text file created

i can only create text file with this command

sc query state= all | find /i "display_name" >>c:\services.txt

 

i want to segregate those services that are runnning from services that are not running or stopped

and able to output it in a text file

 

 

please help me thank you po!!

god bless with the script



BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:01:17 PM

Posted 23 April 2013 - 12:19 PM

I would argue that the command processor is not the best tool to accomplish this job; you can't really take the output of a command and modify it in any way with the plain command processor.

Scripts which do this kind of thing usually require a regular expression tool (at least), such as grep or awk, be installed on the target box first.

The command find finds lines which match the given predicate; but that's what you need. You need the line that matched the predicate and lines around that, which is not supported by that command.

Have you considered PowerShell?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 heltune

heltune
  • Topic Starter

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:04:17 PM

Posted 23 April 2013 - 12:34 PM

so i cant make a batch file in that way?

 

i thought it was simple

because i was able to do this in WMIC

 

output:C:\InstallList.txt product get name,version

 

where i can list all installed softwares

 

howd i wish i can :(

 

anyway thank you for the reply

 

i havnt tried power shell, sorry



#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:01:17 PM

Posted 23 April 2013 - 01:09 PM

A vbs script can access WMI quite easily, and should give you a similar experience to what you'd see via wmic.

 

Batch script isn't a programming language; it isn't even really up to what I'd call a scripting language. This is unlikely to change in the future because any changes to the command processor can/will break an unknowably large number of batch scripts in the wild, and because real CLI development shifted to PowerShell a long time ago. PowerShell comes bundled in most recent versions of Windows in any case, so you really should consider that if you're trying to do "real work" with a batch script like workflow.


Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users