AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1755880
Accepted
Luiz Martins
Luiz Martins
Asked: 2022-12-03 14:30:21 +0800 CST2022-12-03 14:30:21 +0800 CST 2022-12-03 14:30:21 +0800 CST

Windows 资源管理器“打开方式”自定义 powershell 脚本

  • 772

我的目标是能够右键单击一个文件,例如"C:\Users\My PC\folder\file.md",在“打开方式”选项下选择我的自定义脚本,然后使用所述脚本执行该文件。

通过“执行”我的意思是这样的:

# Somehow capture the file path under a variable
$FilePath = ???

# and open it with some terminal program, such as
nvim $FilePath
# or even a non-terminal program, such as
zathura $FilePath

注意:答案不必坚持使用文字Open With选项。允许右键单击文件并选择将使用该文件路径的脚本的任何类似选项(包括来自第三方应用程序的选项)也足够了。

windows
  • 2 2 个回答
  • 46 Views

2 个回答

  • Voted
  1. Best Answer
    w32sh
    2022-12-04T19:37:17+08:002022-12-04T19:37:17+08:00

    这个REG文件可以作为添加右键菜单选项的模板。

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\myscript]
    @="Open with PS Script"
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\myscript\command]
    @="powershell.exe -File \"d:\\scripts\\launch.ps1\" \"%1\""
    
    1. 将以上内容复制到记事本。
    2. 将文件另存为md.reg.
    3. 双击 md.reg并在要求确认时单击“是”。
    4. 右键单击 .md 文件,您将看到“使用 PS 脚本打开”选项。

    根据需要修改 PS 命令行参数——例如,如果您的脚本使用命名参数,请在命令行中相应地添加参数名称。


    选项 2:将多个项目添加为级联菜单

    这是一个模板 REG 文件。

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS]
    "Position"="Middle"
    "Icon"="PowerShell.exe"
    "SubCommands"=""
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell]
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\01subcmd]
    "Icon"="PowerShell.exe"
    "MUIVerb"="Open with Script 1"
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\01subcmd\command]
    @="powershell.exe -File \"d:\\scripts\\launch_1.ps1\" \"%L\""
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\02subcmd]
    "MUIVerb"="Open with Script 2"
    "Icon"="PowerShell.exe"
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\02subcmd\command]
    @="powershell.exe -File \"d:\\scripts\\launch_2.ps1\" \"%L\""
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\03subcmd]
    "MUIVerb"="Open with Script 3"
    "Icon"="PowerShell.exe"
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.md\shell\Open with PS\shell\03subcmd\command]
    @="powershell.exe -File \"d:\\scripts\\launch_3.ps1\" \"%L\""
    

    你得到这个:

    在此处输入图像描述

    有关级联菜单的更多信息:

    1. 如何使用 SubCommands 注册表项创建级联菜单 (Windows) | 微软学习
    2. 使用 ExtendedSubCommandsKey 注册表项创建级联菜单 - Win32 应用程序 | 微软学习
    3. 示例:添加级联菜单选项
    • 2
  2. Luiz Martins
    2022-12-06T11:07:47+08:002022-12-06T11:07:47+08:00

    可能值得大声喊出OpenWithPlusPlus,它是 @w32sh 答案的 GUI 替代品,您可以在一个简单易用的 GUI 界面中创建相同类型的“打开方式...”菜单。一次性的好东西。

    不过,如果您想自动执行此过程,我仍然建议您使用.reg或.ps1文件来更改注册表。

    • 0

相关问题

  • 如何在 Windows Precision 触摸板上禁用鼠标加速?

  • 批量重命名图像文件集

  • Python 的“pass”参数的批处理等价物是什么?

  • 在 Windows 上与 Docker 守护进程通信

  • 资源管理器侧面板中的桌面外壳快捷方式

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve