Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

PowerShell - get process ID of called application

I need to call an external application (i.e. & 'Notepad' ) and then get the process ID of the called application.

Get-Process Notepad = will return all Notepad processes

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!!"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Start-Process with the -PassThru argument like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...