Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 从batchscript关闭powershell窗口_Windows_Powershell_Batch File - Fatal编程技术网

Windows 从batchscript关闭powershell窗口

Windows 从batchscript关闭powershell窗口,windows,powershell,batch-file,Windows,Powershell,Batch File,我想在批处理脚本完成执行后关闭powershell窗口。 这是我的批处理脚本。我尝试了退出命令,但它只关闭命令提示符 @ECHO OFF setlocal EnableDelayedExpansion start PowerShell.exe -Command help powershell.exe -command exit 我想从批处理脚本关闭powershell窗口。我缺少哪个命令?同一行上的多个命令用分号分隔 powershell -NoL

我想在批处理脚本完成执行后关闭powershell窗口。 这是我的批处理脚本。我尝试了退出命令,但它只关闭命令提示符

     @ECHO OFF
     setlocal EnableDelayedExpansion

     start PowerShell.exe -Command help

     powershell.exe -command exit 

我想从批处理脚本关闭powershell窗口。我缺少哪个命令?

同一行上的多个命令用分号分隔

powershell -NoLogo -NoProfile -Command "help; exit"

这是否符合您的要求?

请在CMD提示符中使用下面的代码来关闭现有的PowerShell窗口

taskkill /IM "powershell.exe" /F

仅使用
@PowerShell-Command help
有什么问题?上一个命令将打开一个新的PowerShell进程,并且不会与第一个进程交互。假设您使用的是batch/cmd,您可以通过其PID终止powrshell进程,请参阅:了解一些方法。IAM实际上正在将powershell的帮助读取到一个文件并进行一些处理。在此处理过程中,powershell窗口应打开。批处理文件完成此处理后,我希望关闭批处理脚本末尾的powershell窗口。我不能那样做。我被困在那里。我尝试获取$PID并关闭窗口,但这并不是关闭powershell窗口。如果希望批处理文件等待powershell任务完成,为什么不直接从批处理文件同步调用它?为此,只需省略
start
。是的,但请注意,如果使用
-Command
,会话将在执行命令后自动退出。也就是说,OP的sample命令实际上不会使进程保持活动状态-
-NoExit
。我实际上是将powershell的帮助复制到一个文件中,并在批处理文件中进行一些处理。在所有这些脚本运行之后,我希望在脚本末尾关闭powershell窗口。我可以使用exit关闭cmd提示符,但powershell窗口仍保持活动状态。我想关闭powershell窗口。这就是我被卡住的地方。@codewarrior-如果你只是简单地离开
start
,会发生什么?PowerShell命令将运行并退出。这将终止所有PowerShell进程,这可能是不需要的。