Using Powershell to open CMD script and after that closing with the Powershell script, leaves a phantom window. #21036

Closed
opened 2026-01-31 07:31:17 +00:00 by claunia · 2 comments
Owner

Originally created by @NekoJonez on GitHub (Jan 2, 2024).

Windows Terminal version

1.18.3181.0

Windows build number

10.0.22621.0

Other Software

VSCode
Microsoft Office 365
TeamViewer
Synlogy Drive

I run the latest stable version of VSCode and I run PowerShell 7.4. (I have also written my script in PowerShell 7)

Steps to reproduce

I have written a Powershell script that calls upon a "CMD" file that checks if Microsoft Access is opened or not. If MS Access is opened, the CMD script will close it. That way my Powershell script can copy all the right files and move them over to our Synlogy Drive folder to back them up.

Now, I open the CMD file with this line in Powershell:

$CmdProcess = Start-Process -FilePath "cmd.exe" -ArgumentList "/c `"C:\Users\****\CloseAccess.bat`"" -PassThru

At the end of my Powershell script I have:

    Stop-Process -Id $CmdProcess.Id -Force
    Stop-Process -Name WindowsTerminal -Force -ErrorAction SilentlyContinue  

Expected Behavior

You would think that the script is closed and no other window is left behind.

Actual Behavior

Yet, this isn't the case. You are left with this:
image

When you click on the "X" button, nothing happens. You really need to open one tab, and then you can close it.

Strange thing is that when you run:

    Stop-Process -Name WindowsTerminal -Force -ErrorAction SilentlyContinue  

when you just have the terminal open, no problem.

Now, it gets even stranger. When you comment out the line to kill the CmdProcess.ID ... The batch file keeps running... Even adding:

Stop-Process -Name cmd -Force -ErrorAction SilentlyContinue

doesn't help.

I don't know if this is a Powershell bug or a terminal bug or both...?

Originally created by @NekoJonez on GitHub (Jan 2, 2024). ### Windows Terminal version 1.18.3181.0 ### Windows build number 10.0.22621.0 ### Other Software VSCode Microsoft Office 365 TeamViewer Synlogy Drive I run the latest stable version of VSCode and I run PowerShell 7.4. (I have also written my script in PowerShell 7) ### Steps to reproduce I have written a Powershell script that calls upon a "CMD" file that checks if Microsoft Access is opened or not. If MS Access is opened, the CMD script will close it. That way my Powershell script can copy all the right files and move them over to our Synlogy Drive folder to back them up. Now, I open the CMD file with this line in Powershell: ``` $CmdProcess = Start-Process -FilePath "cmd.exe" -ArgumentList "/c `"C:\Users\****\CloseAccess.bat`"" -PassThru ``` At the end of my Powershell script I have: ``` Stop-Process -Id $CmdProcess.Id -Force Stop-Process -Name WindowsTerminal -Force -ErrorAction SilentlyContinue ``` ### Expected Behavior You would think that the script is closed and no other window is left behind. ### Actual Behavior Yet, this isn't the case. You are left with this: ![image](https://github.com/microsoft/terminal/assets/4569581/1eaab783-e5ea-464e-b256-1815bb06e517) When you click on the "X" button, nothing happens. You really need to open one tab, and then you can close it. Strange thing is that when you run: ``` Stop-Process -Name WindowsTerminal -Force -ErrorAction SilentlyContinue ``` when you just have the terminal open, no problem. Now, it gets even stranger. When you comment out the line to kill the CmdProcess.ID ... The batch file keeps running... Even adding: ``` Stop-Process -Name cmd -Force -ErrorAction SilentlyContinue ``` doesn't help. I don't know if this is a Powershell bug or a terminal bug or both...?
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 07:31:17 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jan 3, 2024):

Yea this is a bit of a tricky one we're tracking in #15936. The easiest fix to get out of this state is to open a new tab, then close the window that way. You can follow #15936 for more updates. Thanks!

/dup #15936

@zadjii-msft commented on GitHub (Jan 3, 2024): Yea this is a bit of a tricky one we're tracking in #15936. The easiest fix to get out of this state is to open a new tab, then close the window that way. You can follow #15936 for more updates. Thanks! /dup #15936
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Jan 3, 2024):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (Jan 3, 2024): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report! <!-- Policy app identification https://img.shields.io/static/v1?label=PullRequestIssueManagement. -->
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21036