简体   繁体   中英

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

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.

以管理员身份运行cmd控制台,然后运行“ sc query type = service state = all”

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

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

I don't know if this will help you but you can see a list of running services by going into the cmd line and inputting net start

That will give you a nice list of what is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM