2011-01-21 53 views
19

我需要调用外部应用程序(即&“记事本”) ,然后获取被调用应用程序的进程ID。PowerShell - 获取被调用应用程序的进程ID

获取进程记事本=将返回所有记事本进程

我想要做的事,如:

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

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

回答

37

使用Start-Process-PassThru说法是这样的:

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

什么是passthru? – 2016-04-08 07:41:25

1

更简洁:

# Starts Notepad and returns the ID 
(Start-Process Notepad -passthru).ID 
相关问题