Skip to main content

进程与服务管理

查看进程​

tasklist                     :: 查看进程列表
tasklist | findstr nginx :: 按名称过滤
tasklist /fi "imagename eq chrome.exe" :: 过滤指定程序
tasklist /svc :: 查看进程对应服务
wmic process list brief :: 更详细信息(PID、内存、窗口)

PowerShell 等价:

Get-Process                 # 进程列表
Get-Process chrome | Sort-Object WorkingSet64 -Descending # 按内存排序
Get-Process -Name chrome -FileVersionInfo # 进程对应的程序版本
Get-CimInstance Win32_Process | Select-Object Name, ProcessId, ExecutablePath

结束进程​

taskkill /im chrome.exe      :: 按名称结束全部
taskkill /pid 1234 :: 按 PID 结束
taskkill /F /pid 1234 :: 强制结束 ⚠️
taskkill /F /im notepad.exe :: 强制按名称结束

PowerShell:

Stop-Process -Name chrome -Force
Stop-Process -Id 1234 -Force

端口占用时:netstat -ano | findstr :8080 找 PID,再 taskkill /F /pid <PID> 释放端口。

服务管理(老工具)​

net start                  :: 查看已启动服务
net start nginx :: 启动服务
net stop nginx :: 停止服务
net stop wuauserv :: 停止 Windows Update 服务
sc query nginx :: 查看服务状态
sc start / sc stop nginx :: 启动/停止
sc config nginx start=auto :: 设置开机自启
sc config nginx start=disabled :: 禁用
sc delete nginx :: 删除服务 ⚠️

服务管理(PowerShell 推荐)​

Get-Service                # 查看全部服务
Get-Service | Where-Object Status -eq Running
Get-Service nginx
Start-Service nginx
Stop-Service nginx
Restart-Service nginx
Set-Service nginx -StartupType Automatic # 开机自启
Set-Service nginx -StartupType Disabled # 禁用

计划/启动​

services.msc               :: 打开服务管理界面
msconfig :: 系统配置(管理启动项,Win10/11 移到任务管理器)
reg query HKLM\...\Run :: 查询启动项(见计划任务篇)

重启 / 关机​

shutdown /s /t 0           :: 立即关机
shutdown /r /t 0 :: 立即重启
shutdown /r /t 60 /c "msg" :: 60 秒后重启并提示
shutdown /a :: 取消关机
logoff :: 注销当前用户

PowerShell:

Restart-Computer
Stop-Computer

系统级(需要管理员)​

sfc /scannow              :: 扫描并修复系统文件(详见维护篇)
dism /online /cleanup-image /restorehealth :: 修复系统映像根因
msiexec /i xxx.msi :: 静默装包(见软件篇)