简体   繁体   English

PowerShell - 获取被调用应用程序的进程ID

[英]PowerShell - get process ID of called application

I need to call an external application (ie & 'Notepad' ) and then get the process ID of the called application. 我需要调用外部应用程序(即&'Notepad'),然后获取被调用应用程序的进程ID。

Get-Process Notepad = will return all Notepad processes Get-Process Notepad =将返回所有记事本进程

I want to do something like: 我想做的事情如下:

$objApp = & 'c:\Notepad.exe'

WHILE (get-process -ID $objApp.id | select -property Responding) {
  Start-Sleep -s 10
  Echo "STILL WAITING"
}
Echo "Done!!"

Use Start-Process with the -PassThru argument like this: Start-Process-PassThru参数一起使用,如下所示:

$app = Start-Process notepad -passthru
Wait-Process $app.Id

More succinct: 更简洁:

# Starts Notepad and returns the ID
(Start-Process Notepad -passthru).ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM