Jump to content
Sign in to follow this  
laidback01

parsing output from sc

Recommended Posts

On your pc, try running "sc query" in a terminal. You'll get a lot of output. Sc is the Service Control interface for the command line and it's in all win2k and winxp machine, I think win2k3, but haven't tested that yet.

Anyway, I realize I can do a dump to a file : sc query > file and parse that for the info I want, however I really don't feel like making files everywhere I run this script. Is there a way to gather that output into a string or variable of some sort and work with it then?

thanks,

Jack

Share this post


Link to post
Share on other sites

#include <Constants.au3>

$foo = Run(@ComSpec & " /c sc query", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
WEnd

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
WEnd

MsgBox(0, "Debug", "Exiting...")



Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

On your pc, try running "sc query" in a terminal. You'll get a lot of output. Sc is the Service Control interface for the command line and it's in all win2k and winxp machine, I think win2k3, but haven't tested that yet.

Anyway, I realize I can do a dump to a file : sc query > file and parse that for the info I want, however I really don't feel like making files everywhere I run this script. Is there a way to gather that output into a string or variable of some sort and work with it then?

thanks,

Jack

Services are available through the WMI COM objects. Why run sc.exe at all?

Functions are available from a UDF called _NTServices.au3, and you can search for many examples of doing it with direct COM calls to the WMI.

If you have Scriptomatic for VBS already, you're almost there. You can find the WMI call you want and just translate to AutoIt.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Services are available through the WMI COM objects. Why run sc.exe at all?

Functions are available from a UDF called _NTServices.au3, and you can search for many examples of doing it with direct COM calls to the WMI.

If you have Scriptomatic for VBS already, you're almost there. You can find the WMI call you want and just translate to AutoIt.

:)

that's pretty nice and all, but SC.exe allows me to permanently disable the service as well.

Thanks for the posts folks, this looks to be the direction I'm after!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...