How to get a list of all services on Windows 7?

10,001

Solution 1

You can use Win API OpenSCManager function and then enumerate services and theirs statuses with EnumServicesStatus

There is a complete reference for Services API on Dev Center

Solution 2

run the cmd console as admnistrator and then run "sc query type= service state= all"

Solution 3

Download the tool Wmi Code Creator. It will help you craft your WMI queries in C#, VB.Net or Visual Basic Script.

Here is a solution using VBScript

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 "Win32_Service instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DisplayName: " & objItem.DisplayName
Next

What is WMI? (From http://technet.microsoft.com/en-us/library/ee692772.aspx)

Windows Management Instrumentation is a core Windows management technology; you can use WMI to manage both local and remote computers. WMI provides a consistent approach to carrying out day-to-day management tasks with programming or scripting languages. For example, you can:

* Start a process on a remote computer.
* Schedule a process to run at specific times on specific days.
* Reboot a computer remotely.
* Get a list of applications installed on a local or remote computer.
* Query the Windows event logs on a local or remote computer.

The word “Instrumentation” in WMI refers to the fact that WMI can get information about the internal state of computer systems, much like the dashboard instruments of cars can retrieve and display information about the state of the engine. WMI “instruments” by modeling objects such as disks, processes, or other objects found in Windows systems. These computer system objects are modeled using classes such as Win32_LogicalDisk or Win32_Process; as you might expect, the Win32_LogicalDisk class models the logical disks installed on a computer, and the Win32_Process class models any processes currently running on a computer. Classes are based on the extensible schema called the Common Information Model (CIM). The CIM schema is a public standard of the Distributed Management Task Force (http://www.dmtf.org).

WMI capabilities also include eventing, remoting, querying, views, user extensions to the schema, instrumentation, and more. http://technet.microsoft.com/en-us/library/ee692772.aspx

Share:
10,001
Zerobinary99
Author by

Zerobinary99

Updated on June 04, 2022

Comments

  • Zerobinary99
    Zerobinary99 almost 2 years

    Is there a way to get a complete list of all services in Win 7 without having to install APIs such as Net Framework 4? I want to get the list as natively as possible.

  • Zerobinary99
    Zerobinary99 about 12 years
    Thank you for your answer. I'm still hoping for an API solution though, since using the command line programmatically is a bit of an ugly solution.
  • Zerobinary99
    Zerobinary99 about 12 years
    Thanks! This is exactly what I need :)
  • Zerobinary99
    Zerobinary99 about 12 years
    Thanks for your reply, but I want to avoid additional software for this solution.
  • gkd720
    gkd720 about 12 years
    @Zerobinary99, I should have clarified. WMI comes builtin with Windows. To make WMI queries, you dont need to install any additional software. I asked you to download the tool to help WRITE the queries. You could instead choose to google for available classes in WMI and their properties. OR you could use to tool to interactively find what you need. Once you have crafted the query you want, you do not need to install ANY tool on the client/users computer. VBScript and WMI are pre-installed on Windows.
  • Zerobinary99
    Zerobinary99 about 12 years
    Thank you for the clarification. That does make WMI a whole lot more attractive. I'm not sure which operating systems are supported by that method. The API function call I settled with is supported by Windows 2000 and newer. It's also the safer bet when dealing with nlited/vlited systems. Anyway, you sparked my interest in WMI now. Thank you for that :)