Windows 服务器运行缓慢、远程桌面卡死或 CPU 长期占用 100%,通常是某个进程占满了资源、内存耗尽或磁盘过于繁忙。本文介绍如何在 Windows Server 2016、2019、2022 和 2025 上用任务管理器、资源监视器和 PowerShell 找出原因,如何区分正常的系统活动与真正的问题,以及如何发现挖矿程序等可疑程序。
按 Ctrl+Shift+Esc 打开任务管理器(在远程桌面中请按 Ctrl+Alt+End,再选择“任务管理器”)。点击详细信息(More details),然后在进程(Processes)或详细信息(Details)选项卡中按 CPU、内存或磁盘排序。在详细信息(Details)选项卡中右键单击列标题,选择选择列(Select columns)并勾选命令行(Command line),即可看到每个进程实际执行的完整命令。
如需进一步分析,可以打开资源监视器(Resource Monitor,resmon)。它的 CPU 选项卡会显示每个 svchost.exe 中运行着哪些服务,磁盘选项卡显示正在读写哪些文件,网络选项卡则显示哪个进程正在与哪个远程地址通信。
即使桌面卡得难以操作,PowerShell 通常仍然可以正常使用。请以管理员身份运行。
# Overall CPU usage, 5 samples 2 seconds apart
Get-Counter '\Processor(_Total)\% Processor Time' -SampleInterval 2 -MaxSamples 5
# Processes using the most CPU right now (percentage of total CPU)
Get-Counter '\Process(*)\% Processor Time' -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty CounterSamples |
Where-Object { $_.InstanceName -notin '_total','idle' } |
Sort-Object CookedValue -Descending | Select-Object -First 10 InstanceName,
@{n='CPU%';e={[math]::Round($_.CookedValue / $env:NUMBER_OF_PROCESSORS, 1)}}
# Processes using the most memory
Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 10 Name, Id,
@{n='RAM(MB)';e={[math]::Round($_.WorkingSet64 / 1MB)}}
# Which services run inside a busy svchost.exe (replace 1234 with its PID)
tasklist /svc /fi "PID eq 1234"
# Free physical memory and committed memory
Get-CimInstance Win32_OperatingSystem |
Select-Object @{n='TotalGB';e={[math]::Round($_.TotalVisibleMemorySize/1MB,1)}},
@{n='FreeGB';e={[math]::Round($_.FreePhysicalMemory/1MB,1)}}
# Disk activity per drive (sustained % Idle Time near 0 means the disk is the bottleneck)
Get-Counter '\LogicalDisk(*)\% Idle Time','\LogicalDisk(*)\Avg. Disk sec/Transfer' -SampleInterval 2 -MaxSamples 3
# Free space per drive
Get-PSDrive -PSProvider FileSystem | Select-Object Name,
@{n='FreeGB';e={[math]::Round($_.Free/1GB,1)}}, @{n='UsedGB';e={[math]::Round($_.Used/1GB,1)}}
如果“使用中”(In use)的内存接近 100%,同时磁盘持续繁忙,说明服务器正在把内存分页到磁盘:请增加内存,或减少服务器上运行的程序。系统盘空间快满时同样会拖慢 Windows,还可能导致无法安装更新,请参见扩展 C 盘。
如果某个进程名称是随机字符,或从 C:\Users\Public、C:\ProgramData、临时文件夹中运行,又或者是没有数字签名却占满 CPU 的可执行文件,就需要仔细检查。挖矿程序经常伪装成 svchost.exe 并放在错误的目录中,而真正的 svchost.exe 只会从 C:\Windows\System32 运行。
# Path, command line and digital signature of a suspicious process (replace 1234)
Get-CimInstance Win32_Process -Filter "ProcessId=1234" | Select-Object Name, ExecutablePath, CommandLine
Get-AuthenticodeSignature (Get-Process -Id 1234).Path | Select-Object Status, SignerCertificate
# svchost.exe copies running from anywhere other than System32 or SysWOW64
Get-CimInstance Win32_Process -Filter "Name='svchost.exe'" |
Where-Object { $_.ExecutablePath -notmatch 'C:\\Windows\\(System32|SysWOW64)\\' } |
Select-Object ProcessId, ExecutablePath
# Network connections per process
Get-NetTCPConnection -State Established | Group-Object OwningProcess |
Sort-Object Count -Descending | Select-Object -First 10 Count, Name
# Persistence: scheduled tasks, auto-start services and startup entries
Get-ScheduledTask | Where-Object { $_.State -ne 'Disabled' -and $_.TaskPath -notlike '\Microsoft\*' } |
Select-Object TaskName, TaskPath, @{n='Action';e={$_.Actions.Execute}}
Get-CimInstance Win32_Service | Where-Object { $_.StartMode -eq 'Auto' -and $_.PathName -notmatch 'Windows' } |
Select-Object Name, State, PathName
Get-CimInstance Win32_StartupCommand | Select-Object Name, Command, Location
# Update signatures and run a full Microsoft Defender scan
Update-MpSignature
Start-MpScan -ScanType FullScan
Get-MpThreatDetection
如果确认存在恶意程序,请先删除对应的计划任务或服务,再结束进程并删除其文件,然后修改所有密码,并堵住入侵途径(最常见的是远程桌面弱密码):参见 Windows VPS 安全加固和修改远程桌面端口。如果无法确定是否已清理干净,请备份数据后重装系统。
时有时无的问题,更适合通过录制性能数据来捕捉。运行 perfmon,展开数据收集器集 → 系统(Data Collector Sets → System),右键单击 System Performance,选择开始(Start)。收集完成后(约一分钟),在报告 → 系统(Reports → System)下生成的报告会列出 CPU、磁盘和网络占用最高的进程。
开启显示所有用户的进程(Show processes from all users),并查看详细信息(Details)选项卡,系统服务和其他用户的进程都会显示在这里。有些恶意程序在任务管理器打开时会自动停止运行,此时可以使用上面的 PowerShell 命令;如果你的产品提供资源监控图表,也可以在 IMIDC 客户中心查看。
如果 CPU、内存和磁盘都正常,原因通常在你和服务器之间的网络线路上。请参见远程桌面连接故障排查,并用 ping 和 tracert 测试路由。
如果在正常访问量下,你自己的应用程序本来就会用掉大部分 CPU 或内存,那么优化也只能撑一时。请升级套餐,或把数据库迁移到另一台服务器上。
如果按以上步骤操作后问题仍未解决,请提交工单联系 IMIDC 7×24 技术支持,并附上服务器 IP、Windows Server 版本、占用高的进程名称,以及任务管理器截图或 PowerShell 输出结果,方便工程师快速定位。