Using sc to list services and their startup type in order on Windows Server

I'm looking to use sc to list all of the services (alphabetically) on a system and display their start-up type. Any ideas? I looked at the helped syntax but didn't know if it might require power shell?
LVL 3
adamshieldsAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
How about this?

wmic service get caption,startmode|sort

~bp
0
 
Bill PrewCommented:
We should be able to do this with a BAT script, can you give a small sample of what you want the output to look like?

~bp
0
 
adamshieldsAuthor Commented:
I was hoping to be able to use a one liner to take care of it but that doesn't seem like it's going to happen that easily with powershell as I'm unable to get it to list the startup types.

Get-Service * |Sort Name

The code below is close but it needs to sort the services names alphabetically first.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "StartMode: " & objItem.StartMode
Next

Open in new window

0
 
adamshieldsAuthor Commented:
Thanks!
0
 
Bill PrewCommented:
Welcome, glad that was useful.

~bp
0
All Courses

From novice to tech pro — start learning today.