网上有一些解决方案,但大多数只是在右键单击文件夹时添加命令。我找到了一个解决方案(两者都有效),用于以管理员身份运行这里。但它仅适用于管理员访问。
答案1
解决方案如下:
这会将 powershell 添加到打开的窗口(即右键单击文件时)
[HKEY_CLASSES_ROOT\Directory\shell]
1. Create a key such as "powershell" or whatever you want without space
2. Set the default value of the key as your desired text, e.g.:"PS here dear"
3. Create a nested key inside the "powershell" key as "command"
4. Edit the command value by this:
C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%L'
这会将 powershell 添加到文件夹内的右键菜单中
[HKEY_CLASSES_ROOT\Directory\Background\shell]
1. Create a key such as "powershell" or whatever you want withuout space
2. Set the default value of the key as your desired text e.g "PS here dear"
3. Create a nested key inside the "powershell" key as "command"
4. Edit the command value by this:
C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'
注意命令中的 %V 和 %L 差异
答案2
这是SdidS 的解决方案作为 regedit 文件:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here]
@="PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'"
答案3
在 PowerShell 中执行以下脚本以添加到上下文菜单:
'Directory',
'Directory\Background',
'Drive' | ForEach-Object {
$Path = "Registry::HKEY_CLASSES_ROOT\$_\shell\PowerShellHere";
New-Item -Path $Path -Name 'command' -Force | Out-Null;
Set-ItemProperty -Path "$Path\command" -Name '(default)' -Value 'PowerShell -WindowStyle Maximized -NoExit -NoLogo -Command Set-Location "%V"';
Set-ItemProperty -Path $Path -Name '(default)' -Value 'PowerShell';
Set-ItemProperty -Path $Path -Name 'Icon' -Value "${Env:WinDir}\System32\WindowsPowerShell\v1.0\powershell.exe,0";
}