powershell
I have powershell script that calls another .exe file. Start-Process ".file.exe" -wait
file.exe is a simple windows with some message and has one only button to close the the .exe.
This is the first line in the main script runs. I want to wait and let the user to click close to proceed with the rest of the code.
However, the process starts, but the main program does not wait and starts executing the rest of the code.
Is there something else I need to do?
not sure if this is what you're looking for, but you can use NSI wrapper to run the first script using ExecWait "powershell -File .file.exe"
and that should do the job.
run any other script after that and it will do what you're looking for.
This recommendation is possibly not the best approach, but came to mind with starting a process. The trick is letting the script know that the other process is running, and it must be communicated that the other process has finished. One method is to have the EXE communicate by writing to a file right before it closes, the script is constantly reading the file waiting for a certain output entered by the EXE. This is dirty though, so another way is to use Windows Forms in Powershell and call the form in PowerShell instead of an EXE (I can elaborate if needed). My third solution is probably the easiest to implement, but not the cleanest. Before launching the EXE, get all processes and store them in an array. Then I would launch the EXE and get processes again, but this time looking for the one that is not in that array. This will likely be your EXE, which you can have the script then look for in a while loop and wait for that process to drop. Example:
$processes = (Get-Process).Id
Start-Process ".file.exe"
Start-Sleep -Seconds 1
$exeProc = (Get-Process).Id | ?{$processes -notcontains $_}
$running = (Get-Process | ?{$_.Id -match $exeProc}).Id
while($running){
Start-Sleep -Seconds 1
$running = (Get-Process | ?{$_.Id -match $exeProc}).Id
}
Start-Process seems to create a new window for the process, even though you specify the -Wait switch.
What has worked for me before is adding a -NoNewWindow switch to Start-Process
Try
Start-Process ".file.exe" -NoNewWindow -Wait
链接地址: http://www.djcxy.com/p/89658.html
上一篇: 进程没有运行
下一篇: 电源外壳