承接上文win_add_powershell_prompt_in_right_click – 水铝英石 (allophane.com)
Win+R regedit
进\HKEY_CLASSES_ROOT\Directory\Background\shell\里添加runas项,再在里面添加command项
- \HKEY_CLASSES_ROOT\Directory\Background\shell\
- runas
- commad
- runas
然后在runas项里新建字符串值和DWORD值:
名称 | 类型 | 数据 |
默认 | REG_SZ | ps_prompt_admin |
Icon | REG_SZ | D:\ProgramData\Anaconda3\Menu\Iconleak-Atrous-PSConsole.ico |
在command里添加字符串值
名称 | 类型 | 数据 |
默认 | REG_SZ | powershell.exe -ExecutionPolicy ByPass -NoExit -Command “& ‘D:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1’ ; conda activate ‘D:\ProgramData\Anaconda3’ ; Set-Location -literalPath ‘%V'” |
ShowBasedOnVelocityId 这个值用来更改显示状态与隐藏状态(HideBasedOnVelocityId),其实不添加也可以。
其中 runas的 Icon 和 command 的默认值 可以从快捷方式中的 目标 和 图标 中获取,并且需要修改 目标 中的代码

icon没什么好说的,主要解释一下脚本:
这个是powershell prompt原脚本的内容
powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'D:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'D:\ProgramData\Anaconda3' "
powershell.exe | 调用 |
-ExecutionPolicy ByPass | powershell对于脚本的执行有着严格的安全限制, 策略 Policies状态分类:Restricted / AllSigned / RemoteSigned / Unrestricted / Bypass / Undefined 设置成Bypass相当于临时使用模式,执行策略权限较低 |
-NoExit | 相当于打开命令行后不退出窗口 |
-Command | 相当于直接执行后续的脚本内容, “&”运算符可以定义为调用 PowerShell 中的命令、脚本文件、函数和可操作程序的运算符 相当于: 1. 执行conda-hook.ps1的脚本,配置anaconda环境变量 2. conda activate 这句相当于启动默认的base环境 |


而一般来说如果管理员调用的话,会直接蹦到system32目录,这也是难以避免的,但是我们其实更希望打开就在目录下
于是在此基础上添加Set-Location,将当前PowerShell的工作位置设置为指定位置
-LiteralPath参数用于指定一个或多个位置的路径。
Set-Location -literalPath '%V'
最后得到上面表格里的形式
powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'D:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'D:\ProgramData\Anaconda3' ; Set-Location -literalPath '%V'"
页面: 1 2