winutil icon indicating copy to clipboard operation
winutil copied to clipboard

Shift+Right-Click context menu "Open in Terminal" and "Open in PowerShell" break

Open Compleur opened this issue 1 year ago • 4 comments

Describe the bug

Shift+Right-Click context menu "Open in Terminal" and "Open in PowerShell" break with brackets or spaces in folder names. This may be related to 'Set-Location' and/or 'cd' commands

Steps to reproduce

PowerShell Example Error:

  1. Open Folder with a space in the directory location (e.g. "C:\Users\USER\ex ample"
  2. Shift + Right-Click context menu -> "Open PowerShell Window Here"
  3. PowerShell opens and outputs an error:
Set-Location : A positional parameter cannot be found that accepts argument 'ample'.
At line:1 char:1
+ Set-Location -literalPath C:\Users\USER\ex ample
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Note that "Open in Terminal" option works in this example as it should.

Terminal Example Error:

  1. Open Folder with a space in the directory location (e.g. "C:\Users\USER[example"
  2. Right-Click context menu -> "Open in Terminal" 3a. PowerShell opens and defaults to "C:>" 3b. If PowerShell is given the command "cd "C:\Users\USER[example" or "Set-Location "C:\Users\USER[example""
Set-Location : The specified wildcard character pattern is not valid: [example
At line:1 char:1
+ Set-Location "C:\Users\USER\[example"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-Location], WildcardPatternException
    + FullyQualifiedErrorId : RuntimeException,Microsoft.PowerShell.Commands.SetLocationCommand

Note that "Open PowerShell Window Here" option works in this example as it should.

Expected behavior

Powershell Should open with the current working location as it's set specified location

Screenshots

Errors are written out in "Steps to Reproduce"

Additional context

For "Open PowerShell Here," my guess is that a command in the registry is broken due to not including quotation marks. I checked under "HKEY_CLASSES_ROOT\directory\background\shell\Powershell\command" and found the data value " powershell.exe -noexit -command Set-Location -literalPath "%V" ". from online sources I noticed that "%L" would be used, but I'm not sure what the difference is due to my inexpertise in this.

For the bracket wildcard error(?), I am curious if this could be a similar issue? I am out of my depth here.

Issue validation

  • [ X ] I checked for duplicate issues.
  • [ X ] I checked for already existing discussions.
  • [ X ] I checked for an already existing pull request addressing the issue.

I can't find anything related to this issue.

Edited for Better Formatting

Compleur avatar Jan 26 '25 15:01 Compleur

I found this bug while using the native Shift+Right-click > Open PowerShell window here so I think it's a native issue that has been passed to winutil.

I also reported it via Windows feedback just in case.

hsandt avatar Feb 10 '25 13:02 hsandt

It is a native issue, I don't have winutil and also have it.

ShizCalev avatar Feb 11 '25 12:02 ShizCalev

Figured it out lmao

Computer\HKEY_CLASSES_ROOT\Directory\background\shell\Powershell\command Computer\HKEY_CLASSES_ROOT\Drive\shell\Powershell\command You'll need to edit these two registry keys from powershell.exe -noexit -command Set-Location -literalPath '%L' to powershell.exe -noexit -command Set-Location -LiteralPath '%V' (You may have to take ownership of the regkey to edit it first.)

Microsoft messed up the case sensitive -LiteralPath param, and %V fixes space handling.

ShizCalev avatar Mar 03 '25 06:03 ShizCalev

@ShizCalev Thank you for the fix, much appreciated!

Stickerpants avatar Apr 23 '25 00:04 Stickerpants

nothing to do here /close

Marterich avatar May 22 '25 18:05 Marterich