Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell 7 Windows Explorer context menu options to open a shell at the current directory do not work properly (with fix) #14091

Closed
rlusian1 opened this issue Nov 13, 2020 · 5 comments
Labels
Area-Maintainers-Build specific to affecting the build Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-No Activity Issue has had no activity for 6 months or more

Comments

@rlusian1
Copy link

Steps to reproduce

  • Install Powershell 7 and have it add the context menus to open PowerShell at the current location
  • Open Windows Explorer and go to a directory other than your Env::USERPROFILE (say c:\temp)
  • Use the PowerShell7 > Open Here or Open Here as Administrator options
  • Powershell starts up at Env:USERPROFILE

Expected behavior

  • Powershell should start up in the directory where the context menu was used (such as c:\temp)

Actual behavior

  • Powershell always starts at Env::USERPROFILE

Fix

The problem here is that the registry command sets the WorkingDirectory, but that is not the same as the directory where the shell is opened to. You also need to do a Set-Location.

This is the command as laid down by WIX in Product.wxs

C:\Program Files\PowerShell\7\pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory "%V!" -Command "$host.UI.RawUI.WindowTitle = 'PowerShell 7 (x64)'"

This is a command that actually works:

[HKEY_CLASSES_ROOT\Directory\ContextMenus\PowerShell7x64\shell\openpwsh\command]
@="C:\Program Files\PowerShell\7\pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory "%V!" -Command "$host.UI.RawUI.WindowTitle = 'PowerShell 7 (x64)'; $wdtemp=[Environment]::CurrentDirectory; Set-Location -Path $wdtemp""

As noted above, you need to do a Set-Location to get the shell to open in the desired directory. This is complicated by the issue that -RemoveWorkingDirectoryTrailingCharacter was designed to fix, but that switch does not work with Set-Location. The solution was to set the -WorkingDirectory with -RemoveWorkingDirectoryTrailingCharacter (which sets [Environment]::CurrentDirectory properly), then read that into a variable and pass that to Set-Location.

Since this is a strange sequence of commands and there might be a better way to do it, I'm leaving the final fix to the experts, but this does produce the desired behavior.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@rlusian1 rlusian1 added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Nov 13, 2020
@iSazonov iSazonov added the Area-Maintainers-Build specific to affecting the build label Nov 14, 2020
@iSazonov
Copy link
Collaborator

I can not reproduce the issue.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Maintainers-Build specific to affecting the build Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-No Activity Issue has had no activity for 6 months or more
Projects
None yet
Development

No branches or pull requests

2 participants