elm*_*nty 6 windows powershell contextmenu
似乎 Windows 唯一一次在 ps1 文件的内容菜单中显示“使用 PowerShell 运行”是在默认应用程序是记事本时。如果我将默认应用程序更改为 PowerShell ISE(或任何其他编辑器,就此而言),则不会出现“使用 PowerShell 运行”上下文项。
Windows 7 专业版 SP1,WMF 4.0
小智 7
在 Windows 10 中按“开始”,然后键入“默认应用设置”,单击“默认应用设置”。出现一个新窗口“按文件类型选择默认应用程序”。滚动到“.ps1”。单击当前应用程序图标,然后选择记事本。
正如 elmonty 所说,当右键单击 ps1 文件时,这将恢复“使用 PowerShell 运行”上下文菜单条目。
您可以将以下内容复制到文本文件中并导入到您的注册表中。这将打开 PowerShell 控制台并在您双击 ps1 文件时执行脚本。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""
Run Code Online (Sandbox Code Playgroud)
或打开 regedit,导航到:
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
Run Code Online (Sandbox Code Playgroud)
双击(默认)字符串条目并在“数值数据:”中输入以下内容:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
Run Code Online (Sandbox Code Playgroud)
我找到了答案。您必须将默认应用程序设置回记事本。这将恢复“使用 PowerShell 运行”上下文项。接下来,您必须直接在注册表中编辑“打开方式”应用程序,此处:
\HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command
将值更改为:
“C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe”“%1”
或者您可以将其更改为您选择的编辑器。
| 归档时间: |
|
| 查看次数: |
3997 次 |
| 最近记录: |