![](/img/trans.png)
[英]How do I get a Powershell process that was opened by another Powershell process?
[英]How do I get the parent id of a process on powershell?
clear
$name = Read-host -Prompt 'Name of service'
$p = Get-process $name
$id = $p.Id
$parentId = $p.Parent.Id
echo $parentId
我試過這個,但它沒有返回任何東西
Get-Process 不包含父 ID,因此您需要使用 Get-CimInstance
clear
$name = Read-host -Prompt 'Name of service'
$ParentProcessIds = Get-CimInstance -Class Win32_Process -Filter "Name = '$name'"
$output = $ParentProcessIds[0].ParentProcessId
Write-Host $output
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.