Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

PowerShell 7 crashes when called with full path

Apr
36
0
I have PowerShell 7 installed on my PC. The current version is 7.6.3.0. There are, as far as I see it, two ways to run it:
  • pwsh
  • C:\Program Files\WindowsApps\.......\pwsh.exe
You can find the full path when searching with Everything. Both ways work when not using TCMD:
  • Windows run dialog (Win+R)
  • Windows Shell (configured as profiles)
  • Using Command Palette of Windows PowerToys
Using TCMD there also are several ways to launch PowerShell 7:
  • TCC command line (running PowerShell inside TCC)
  • Home -> Run App...
  • configuring a Profile
The first one (TCC) works in both cases. The other two only work when using "pwsh". They (or rather PowerShell) crashes when entering the full path into the "Run Program" dialog or as a command in a profile (the setting of ConPTY doesn't matter). Unfortunately the console get closed so fast, that I cannot make a screenshot or even read the error dump. The system, however, created some crash dumps while I was playing around.

So why did I configure PowerShell 7 with the full path anyway? Well... to see its icon.

Screenshot 2026-07-05 090821.webp
 
If I put C:\Program Files\PowerShell\7\pwsh.exe in a profile's command or in Tabs\Run, I get what Dieter got ... too quick to read. In a half-dozen tries, I got no DMP files.

If I use the quoted string "C:\Program Files\PowerShell\7\pwsh.exe" in Tabs\Run it works. If I use that quoted string in a profile's command it fails (as above) and when I return to the profiles tab, the quotes are gone.

When it fails, it's very fast, but from what I can discern, first there is an error message: The argument "Files\PowerShell\7\pwsh.exe" is not recognized as ... and that's followed by a "Usage: pwsh[.exe] ..." message.
 
Powershell isn't crashing, it's exiting because you passed it invalid arguments.

In the Run and Profile dialogs, it's asking for a command line, including any arguments. You're passing it "C:\Program" for the command name, and "Files\PowerShell\7\pwsh.exe" for the arguments. You need to enclose the command name in double quotes if it contains whitespace (like you need to for every other command in TCC & TCMD).
 
This doesn't work for a profile but it does for Run. For a profile it behaves as I described earlier.

1783289643287.webp
 
You've probably figured this out by now, but this is the momentary tab I see, and how to get it.

1783340138293.webp
 
OK, I think I figured out what is happening and what was happening when I first stumbled over the issue.

When entering the relevant portion of the profile, it looks like this:

Screenshot 2026-07-06 222426.webp

After pressing OK and reopening the options dialog, it looks like this:

Screenshot 2026-07-06 222445.webp

Can you spot the difference? Yup, the quotes are missing! So when executing the profile entry TCMD doesn't have any quotes around the command.

This is also most probably why Home->Run App didn't work for my the fist time. I simply copied the command from the options dialog and pasted it into the run app dialog, after the profile entry had failed. But at that time the quotes where already gone and I didn't spot the difference.
 
They are remembered in the INI file.

Well yes... but... changing an option in a dialog is a no-go in my book, even if said option is stored correctly. Consider the following:
  1. enter a profile (command has quotes)
  2. save and reload (quotes are gone)
  3. change something else without re-typing the quotes (say, the title)
  4. save again
  5. profile is stored incorrectly and won't work anymore
I think that (3) is the most likely outcome, since most if not all user will not expect that their previous entries are changed by saving and reloading.

Finally, are you absolutely positive, that the command is executed as it is stored in the INI-file. Maybe just maybe it is executed as it is displayed in the dialog. Or maybe it's something else entirely, say not initializing a buffer correctly and executing some garbage at the end of the buffer in addition to the command. Well, I don't know. To verify one needs the source code and a debugger. That is, I think that Rex should have a closer look at what is really going on.

It is hard or even impossible to tell what kind of bug it is, at least from my point of view.
 
I didn't realize that build 71 was already up when posting my last reply. Some testing after upgrading got the following results.

Running PowerShell using the full path seems to work most of the time
  • ConPTY: on and off
  • Quotes: do not matter, that is, it works both with and without quotes
But I experienced two crashes in about two dozen tries. Unfortunately, the console window was closed instantly, so I cannot say what went wrong. Again, I see some crash dumps of pwsh.exe, but I cannot correlate them, because of the next issue. I will try again in an hour and report any new findings.

Running PowerShell using the system alias doesn't work at all in build 71.

Screenshot 2026-07-07 083859.webp


Running that profile I get the following result

Screenshot 2026-07-07 083621.webp


"Das Handle ist ungültig" means an "invalid handle" was returned.

Oh well, I just executed the profile depicted above again, to see if it creates a crash dump again... and now it runs perfectly well (shaking head in disbelieve).

I will try again in an hour or two. Currently I have some long running tasks which I cannot (don't want to interrupt).
 
Well, beats me, I cannot reproduce the crashes I had this morning. But I manged to get another two crash dumps when executing PowerShell from Home -> Run App. The behavior I see, is more or less random.
  1. Using quotes everything seems to work fine.
  2. Using no quotes, that is, using the full path as it displayed in the options dialog, things get funky.
For the 2nd case I get any one of the following results:
  1. PowerShell starts normally
  2. PowerShell hangs and a crash dump is created
  3. TCMD displays an error message: the system cannot find "C:\Program".
This is weird to say the least. A wild guess: If I had to search for a bug, I would look for a badly initialized buffer.

Finally, TCMD stores but still removes any quotes which you enter into the options dialog when creating or changing a profile.
  1. Quotes are store in the INI-file when entered with the command
  2. When closing and re-opening the dialog, the quotes are gone
  3. Now close the dialog by pressing OK (without changing anything)
  4. The quotes are gone even in the INI-file
I have no idea, what the consequences of that behavior are. At the moment, it works fine with or without quotes. But earlier today I had some random crashes.
 
With build 71, I tried 20+ times with Command="C:\Program Files\PowerShell\7\pwsh.exe". They all worked. I also tried several times adding arguments (simple ones). For example,

Command="C:\Program Files\PowerShell\7\pwsh.exe" -nol (-NoLogo)
Command="C:\Program Files\PowerShell\7\pwsh.exe" -noe -c $profile (-NoExit and -Command)

They worked also.

As far as I can tell, if there are no arguments the quotes do not later appear in the profile config dialog, and in that case, OK removes them from the INI file (as @DieterKoessl said) and the command still works. But that leads to some difficulty. If you re-open the dialog (no quotes showing) and add arguments without adding quotes, the command fails. If there are arguments the quotes do later appear in the dialog.
 
I didn't realize that build 71 was already up when posting my last reply. Some testing after upgrading got the following results.

Running PowerShell using the full path seems to work most of the time
  • ConPTY: on and off
  • Quotes: do not matter, that is, it works both with and without quotes
But I experienced two crashes in about two dozen tries. Unfortunately, the console window was closed instantly, so I cannot say what went wrong. Again, I see some crash dumps of pwsh.exe, but I cannot correlate them, because of the next issue. I will try again in an hour and report any new findings.

Running PowerShell using the system alias doesn't work at all in build 71.

View attachment 6048

Running that profile I get the following result

View attachment 6049

"Das Handle ist ungültig" means an "invalid handle" was returned.

Oh well, I just executed the profile depicted above again, to see if it creates a crash dump again... and now it runs perfectly well (shaking head in disbelieve).

I will try again in an hour or two. Currently I have some long running tasks which I cannot (don't want to interrupt).

Not reproducible here.

I don't believe this has anything to do with TCMD. It's just calling the Windows CreateProcess API to execute pwsh.exe. Everything from that point on is Windows + Powershell.
 
Back
Top