Link to home
Create AccountLog in
Avatar of adamshields
adamshieldsFlag for United States of America

asked on

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?
Avatar of Bill Prew
Bill Prew

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
Avatar of adamshields

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks!
Welcome, glad that was useful.

~bp