简体   繁体   English

在其中启动 powershell 后保持批处理脚本运行

[英]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.当我选择做所有事情时,在启动第一个 .ps1 后,它只会杀死我的 cmd 窗口。

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.我找到了一些方法来保持窗口打开,但脚本不会继续......此外,我创建了一个“主文件”来调用所有“.ps1”并尝试了这些 cmds: call, /wait 呼叫功能有效,它们一切开始。 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.下面的 cmd 行在我的脚本中不会相互呼应,因为我希望能够分别调用它们。

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 : master.bat 看起来像这样:

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 设法解决了我的问题

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

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