首页 > 解决方案 > 使用 PowerShell 仅远程终止特定的命令提示符进程

问题描述

我正在尝试编写一个脚本来远程终止特定的命令提示符进程。如果我在本地运行 get-process,我可以看到 CMD.exe 进程可以通过“MainWindowTitle”字段中设置的内容来缩小范围

如果我使用 Get-Process -计算机名称或获取 CIMInstance,则“MainTitleWindow”字段将返回为空白。

$ses = New-CimSession -ComputerName $computer -Credential $cred
$process = Get-CimInstance -ClassName CIM_process -CimSession $ses -filter "name = 'cmd.exe'"
$process | Select-Object name,MainWindowTitle
Remove-CimSession -CimSession $ses


name    MainWindowTitle
----    ---------------
cmd.exe

标签: powershellcommand-promptget-wmiobject

解决方案


摘自MSDN

仅当进程具有图形界面时,进程才具有与之关联的主窗口。如果关联进程没有主窗口(因此 MainWindowHandle 为零),则 MainWindowTitle 为空字符串 ("")。

更多信息在这里

我试图与其他进程进行比较,但结果是一样的......


推荐阅读