powershell - 使用 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
解决方案
摘自MSDN:
仅当进程具有图形界面时,进程才具有与之关联的主窗口。如果关联进程没有主窗口(因此 MainWindowHandle 为零),则 MainWindowTitle 为空字符串 ("")。
更多信息在这里。
我试图与其他进程进行比较,但结果是一样的......
推荐阅读
- javascript - 相当于 Python 列表 (l) 的 Chrome Javascript 调试器
- javascript - 如何使用 javascript 选择“srcset”属性的值?
- python - 如何使 Google Colab 代码适应 AWS lambda 函数?
- dax - 过滤后 Dax 索引列未重置
- python - Python Pytest 是否可以从夹具访问变量?
- python - 缓存和搜索多个请求的 API 响应
- javascript - 我将尝试使用css的顺序每三天循环一次div。我该怎么办?
- java - 如何下载电子邮件附件并将其存储在下载文件夹中?
- json - 错误报告 ExtJS 7.4.0 Ext.data.reader.Json
- ionic-framework - 错误:@capacitor-community/native-audio - 缺少资产路径 [IONIC 5]