您在屏幕上看到的正在运行的应用程序只是Windows中正在发生的事情的一小部分。从管理设备驱动程序到确保安全,一堆后台进程维护着一台正常运行的Windows PC。
对于监督多台计算机的任何系统管理员来说,能够查看这些关键服务的状态非常重要。任务管理器(Task Manager)方法对此太慢了,您无法使用脚本将其自动化。
解决方案?命令行工具。使用命令提示符或 PowerShell(Command Prompt or PowerShell),您可以快速了解系统上运行的可操作Microsoft服务,帮助您快速诊断任何问题。
在命令提示符(Command Prompt)中列出Windows 服务(Services)
虽然不如Windows PowerShell灵活或强大,但命令提示符(the Command Prompt)仍然是系统管理员的绝佳工具。您可以使用queryex命令获取活动和禁用服务的状态,然后使用 taskkill 命令(use the taskkill command)结束讨厌的进程。
- 要使用 queryex 命令,请以管理员身份运行(Administrator)命令提示符(Command Prompt)。您可以通过在开始菜单中搜索 cmd 找到该应用程序。
- 使用 sc queryex 命令的方法有很多种。类型和状态(State)是最常用的两个参数。例如,输入以下命令可查看所有 Windows进程:
sc queryex type=service state=all
- 默认视图可能有点压倒性。您可以只显示进程的名称以使列表更易于解析:
sc queryex type=service state=all | find /i “SERVICE_NAME:”
- 默认情况下,该命令会列出所有活动进程。要查找不活动的,请修改 state 参数:
sc queryex type=service state=inactive
- 您还可以通过名称查询特定进程的状态。这对系统管理员来说非常有用,因为他们可以设置批处理文件来一次检查多个进程。这是一个例子:
sc 查询 DeviceInstall(sc query DeviceInstall)
在PowerShell中列出Windows 服务(Services)
PowerShell旨在成为现代Windows的专用命令行 shell 。因此,它通过命令提供对几乎所有操作系统组件的访问,Windows服务也不例外。
PowerShell的优势在于您可以轻松地将其自动化。所有PowerShell命令都可以编译成复杂的脚本,让您可以轻松地在多台 PC 上设置系统管理任务。
- 首先(Start)打开PowerShell。您可以在开始菜单(Start Menu)中搜索它;只需确保运行提升的实例(即,作为管理员(Administrator))。
- 在PowerShell(PowerShell)上列出Windows服务的最简单命令是Get-Service。它显示您计算机上的所有服务,以及它们的状态和名称。唯一的问题是服务列表可能很长。
- 使用Get-Service时,最好将列表导出到文本文件。您可以使用管道执行此操作,如下所示:
Get-Service | Out-File “C:\logs\All_Services.txt”
- 要查找特定服务的状态,请在Get-Service命令之后使用该服务的名称。您可以通过用逗号分隔它们的名称来请求多个进程的状态。
获取服务 CryptSvc、COMSysApp(Get-Service CryptSvc, COMSysApp)
- 管道还可用于将Get-Service cmdlet 与Where-Object函数结合起来,并按(Where-Object)Status过滤结果。以下命令通过获取所有正在运行(Running)的服务来说明这一点:
Get-Service | Where-Object {$_.Status -EQ “Running”}
检查服务依赖关系
任何复杂的流程都被拆分为多个相互依赖的服务。这就是为什么仅仅获得特定服务的状态通常是不够的。您还需要检查服务所依赖的服务的状态。
- 要查看特定服务所需的服务,请将-RequiredServices标志与Get-Service cmdlet 一起使用。这是一个例子:
Get-Service -Name CryptSvc –RequiredServices
- 同样,要获取依赖于特定服务的服务列表,请利用-DependentServices标志。
Get-Service -Name CryptSvc -DependentServices
这两个标志对于编写脚本以自动启动或停止Windows服务至关重要,因为它们为您提供了一种跟踪与受影响服务连接的所有服务的方法。
列出远程(Remote)计算机上的Windows 服务(Services)
PowerShell方法不限于本地计算机。您也可以使用具有上述相同语法的Get-Service cmdlet 来查询远程 PC 的进程。(Get-Service)只需在(Just)末尾附加-ComputerName标志即可指定要从中检索信息的远程计算机。
这是一个例子:
获取服务 CryptSvc -ComputerName Workstation7(get-service CryptSvc -ComputerName Workstation7)
在PowerShell中管理Windows 服务(Services)
获取服务的状态并不是您在Windows PowerShell(Windows PowerShell)中唯一可以做的事情。作为一个成熟的脚本环境,它提供了所有GUI选项的脚本替代方案。
Powershell cmdlet 可以停止、启动、重新启动甚至修改服务。结合自动化的 Get-Service(Get-Service)命令,可以编写PowerShell脚本以完全自动化日常系统管理任务。(PowerShell)
- 除了查询服务的状态,您还可以使用PowerShell来管理它们。启动或停止服务可以用一个命令完成,只需要服务的名称。例如,这是停止服务的方式:
停止服务名称假脱机程序(Stop-Service -Name Spooler)
- 启动服务的过程类似:
启动服务名称假脱机程序(Start-Service -Name Spooler)
- 如果服务无法正常工作,您还可以选择重新启动它:
重新启动服务名称假脱机程序(Restart-Service -Name Spooler)
- 还有可用于更改服务属性的Set-Service cmdlet。(Set-Service)这里我们禁用Print Spooler(Print Spooler)服务的自动启动:
设置服务“后台处理程序”-StartupType 已禁用(Set-Service ‘Spooler’ -StartupType Disabled)
列出 Windows(List Windows) 服务(Services)的最佳方式是什么?
无论您运行的是Windows 10还是Windows Server,能够查看所有Windows服务的列表都很方便。您可以诊断关键系统功能的问题或停止不必要的 Microsoft 服务以提高性能。
为此,PowerShell是最佳选择。虽然您可以在命令提示符中获取服务列表,但(Command Prompt)PowerShell提供的附加功能更有用。
您可以使用PowerShell cmdlet 获取Windows进程的服务状态,通过它们的状态或其他参数对其进行过滤。确定依赖服务并根据需要启动或停止它们也很容易。
How to List All Windows Services using PowerShell or Command Line
The rυnning applications you see on your screen are a fraction of what iѕ happening in Windows. From managing device drivers to ensuring security, a bunch of background processes maintain a functioning Windows PC.
For any system administrator overseeing multiple computers, it is important to be able to view the status of these critical services. The Task Manager approach is too slow for this, and you cannot automate it with a script.
The solution? Command-line tools. Using the Command Prompt or PowerShell, you can quickly get a read on the operational Microsoft services running on a system, helping you diagnose any issues swiftly.
Listing Windows Services In the Command Prompt
While not as flexible or powerful as Windows PowerShell, the Command Prompt is still an excellent tool for system administrators. You can use the queryex command to get the status of both active and disabled services and then use the taskkill command to end pesky processes.
- To use the queryex command, run Command Prompt as an Administrator. You can find the app by searching cmd in the start menu.
- There are many ways of using the sc queryex command. Type and State are the two most commonly used parameters. For example, enter the following command to view all Windows processes:
sc queryex type=service state=all
- The default view can be a bit overwhelming. You can display just the names of processes to make the list easier to parse:
sc queryex type=service state=all | find /i “SERVICE_NAME:”
- By default, the command lists all active processes. To look for inactive ones, modify the state parameter:
sc queryex type=service state=inactive
- You can also query the status of a specific process by its name. This is incredibly useful for system administrators, as they can set up batch files to check many processes at once. Here’s an example:
sc query DeviceInstall
Listing Windows Services in PowerShell
PowerShell is meant to be a dedicated command-line shell for modern Windows. As such, it provides access to pretty much every operating system component through commands, and Windows services are no exception.
PowerShell’s advantage is that you can automate it easily. All PowerShell commands can be compiled into complex scripts, allowing you to set up system administration tasks on multiple PCs without hassle.
- Start by opening PowerShell. You can search for it in the Start Menu; just make sure to run an elevated instance (i.e., as an Administrator).
- The simplest command for listing Windows services on PowerShell is Get-Service. It shows all services on your computer, along with their status and names. The only problem is that the list of services can be pretty long.
- When using Get-Service, it is a better idea to export the list to a text file. You can do this using pipes, like this:
Get-Service | Out-File “C:\logs\All_Services.txt”
- To look up the status of a specific service, follow the Get-Service command with the name of the service. You can request the status of multiple processes by separating their names with commas.
Get-Service CryptSvc, COMSysApp
- Pipes can also be used to combine the Get-Service cmdlet with the Where-Object function and filter the results by Status. The following command illustrates this by getting all Running services:
Get-Service | Where-Object {$_.Status -EQ “Running”}
Checking Service Dependencies
Any complex process is split into multiple interdependent services. This is why simply getting the status of a particular service is often not enough. You also need to check the status of the services that service is dependent on.
- To view the services required by a particular service, use the -RequiredServices flag with the Get-Service cmdlet. Here’s an example:
Get-Service -Name CryptSvc –RequiredServices
- Similarly, to get a list of services that depend on a specific service, take advantage of the -DependentServices flag.
Get-Service -Name CryptSvc -DependentServices
These two flags are crucial in writing scripts to automatically start or stop Windows services, as they give you a way to keep track of all the services connected with the affected service.
Listing Windows Services On Remote Computers
The PowerShell method is not limited to local computers. You can use the Get-Service cmdlet with the same syntax described above to query the processes of remote PCs as well. Just append the -ComputerName flag at the end to specify which remote computer to retrieve information from.
Here’s an example:
get-service CryptSvc -ComputerName Workstation7
Managing Windows Services in PowerShell
Getting the status of services isn’t the only thing you can do in Windows PowerShell. As a full-fledged scripting environment, it provides script alternatives to all GUI options.
Powershell cmdlets can stop, start, restart, or even modify services. Paired with automated Get-Service commands, PowerShell scripts can be written to fully automate everyday system management tasks.
- In addition to querying the status of services, you can also use PowerShell to manage them. Starting or stopping services can be done with a single command, requiring only the name of the service. For example, this is how you can stop a service:
Stop-Service -Name Spooler
- Starting a service goes similarly:
Start-Service -Name Spooler
- If a service isn’t working correctly, you can also choose to restart it:
Restart-Service -Name Spooler
- There is also the Set-Service cmdlet that can be used to change the properties of a service. Here we disable the automatic startup of the Print Spooler service:
Set-Service ‘Spooler’ -StartupType Disabled
What Is the Best Way to List Windows Services?
Whether you are running Windows 10 or a Windows Server, being able to view a list of all Windows services can be handy. You can diagnose issues with critical system functions or stop unnecessary Microsoft services to improve performance.
For this purpose, PowerShell is the best option. While you can obtain a service list in Command Prompt, the additional functionality provided by PowerShell is more useful.
You can use PowerShell cmdlets to get the service status of Windows processes, filtering them by their status or other parameters. It is also easy to determine dependent services and start or stop them as required.