简体   繁体   中英

Keep batch script running after launching powershell within

I am using a batch script to automate a lot of tasks I have to run on a computer. In the batch file I have a menu making you choose between each task separately or do everything. When I choose to do everything, after launching the first .ps1 it just kills my cmd window.

I found some way to keep the window open but the script doesn't continue... Also I created a "master file" to call all the ".ps1" and tried those cmds: call, /wait The call feature works and they all start. So I don't understand why they would do the same in my script. The cmd lines bellow are not bellow each other in my script because I want to be able to call them separately.

Part of the script I would like to run properly:

echo Windows Layout
start /wait PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dp0Customisation\Export_Import_Layout.ps1""' -Verb RunAs}"

echo Remove Unwanted Apps
start /wait PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dp0Clean\RemoveAppx.ps1""' -Verb RunAs}"
wmic product where name="WinZip 22.5" call uninstall
ping -n 6 localhost >nul
Taskkill /IM /F "MicrosoftEdge.exe"
Taskkill /IM /F "MicrosoftEdgeCP.exe"
Taskkill /IM /F "MicrosoftEdgeSH.exe"
%~dp0Clean\MCPR.exe

The master.bat looks like this :

call PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dp0InstallChocoAndApps.ps1""' -Verb RunAs}"
call PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dp0Clean\RemoveAppx.ps1""' -Verb RunAs}"

Any hint would be appriciated. Please keep in mind I am not a script specialist.

Thanks

Ben

通过添加 start "" /wait 而不是 start /wait 设法解决了我的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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