本文介绍了如何通过其服务名称和脚本来获取进程ID到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为WinDefend
的服务,它在进程svchost.exe
上运行还有许多其他svchost.exe
进程,我需要找到一种获取其ID的方法.
当我运行tasklist /svc
时,我可以看到:
I have service named WinDefend
and it runs on process svchost.exe
There other many svchost.exe
processes and I need to find a way to get its ID.
when I run tasklist /svc
I can see:
我不确定如何获得它.
我找到了此命令,但是当我尝试select "PID"
时,它给了我空的列.
I am not sure how can I get it.
I found this command but when I tried the select "PID"
it gave me empty column.
我需要将进程的PID更改为变量.
I need to get the PID of the process to variable.
推荐答案
tasklist
只是返回文本,而不是具有可访问属性的实际对象.您可以使用WMI来获取此信息:
tasklist
is just returning text, not actual objects that have properties you can access. You can use WMI to get this information instead:
$id = Get-WmiObject -Class Win32_Service -Filter "Name LIKE 'WinDefend'" |
Select-Object -ExpandProperty ProcessId
$process = Get-Process -Id $id
这篇关于如何通过其服务名称和脚本来获取进程ID到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!