簡體   English   中英

如何獲取 powershell 上的進程的父 ID?

[英]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

Powershell 如何通過ProcessID獲取ParentProcessID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM