url2cmd: 一个可以用 URL 协议运行命令的小工具 (不定时更新用法)

本贴最后更新于 848 天前,其中的信息可能已经水流花落

url-run-command

使用 URL 协议运行命令

项目地址: Zuoqiu-Yingyi/url-run-command


用法

若还有其他好用的方法欢迎在评论区留言呀(*^▽^*)

  • 使用视频播放器 Potplayer 打开本地视频并跳转到指定时间点
    • runcmd://PotPlayerMini64.exe 'D:\你的\视频\文件.mp4' /seek=00:10:20.00

原理

  • 将自定义 URL 协议注册为 Windows 系统协议, 并调用一个具有如下功能的程序
    1. 对 URL 载荷进行 URL 解码, 获得指令
    2. 调用系统命令行解析器 CMDPowerShell 运行指令

注意: 为了避免可能出现的 远程命令/代码执行(Remote Command/Code Execution, RCE) 攻击, 请尽量使用足够长的随机字符串作为自定义协议名称

开始

快速开始

  1. Releases 中下载发行包并解压到自定义安装目录
  2. 运行安装目录中的 install.bat 批处理文件
  3. 安装目录中将生成 insert.regdelete.reg 两个注册表文件
    • insert.reg: 安装时将要写入注册表的注册表项
    • delete.reg: 卸载时将要从注册表中删除的注册表项
  4. 允许对注册表的更改
  5. 安装完成
  6. Windows 资源管理器 的地址栏中输入 runcmd://systeminfo; pause 并回车, 检查 URL 协议 runcmd 能否运行命令 systeminfo; pause (查看系统信息后暂停)

高级选项

在安装目录中使用如下命令查看命令行参数

PS > .\url2cmd.exe help
Active code page: 65001
SYNOPSIS
        url2cmd.exe <url> (-c|-p) [--debug] [--parser <path>]
        url2cmd.exe init [-n <scheme>] (-c|-p) [--debug] [--parser <path>]
        url2cmd.exe help

OPTIONS
        <url>       统一资源定位符 / Uniform Resource Locator, URL
        -c, --cmd   使用 CMD 解析器 / use CMD parser
        -p, --powershell, --pwsh
                    使用 PowerShell 解析器 / use PowerShell parser

        --debug     输出调试信息 / output debug information
        --parser    自定义命令解析器 / custom command parser
        <path>      自定义命令解析器路径 / path of custom command parser
        init        初始化注册表文件 / initialize the registry file
        -n, --name  自定义 URL 协议名称 / custom URL scheme name
        <scheme>    协议自定义名称 / name of custom scheme
        -c, --cmd   使用 CMD 解析器 / use CMD parser
        -p, --powershell, --pwsh
                    使用 PowerShell 解析器 / use PowerShell parser

        --debug     输出调试信息 / output debug information
        --parser    自定义命令解析器 / custom command parser
        <path>      自定义命令解析器路径 / path of custom command parser
        help        查看参数指南 / view the parameter guide

开发者选项

git clone https://github.com/Zuoqiu-Yingyi/url-run-command.git

cd url-run-command

g++ \
   src\main.cpp \
   -o dist\url2cmd \
   -g \
   -static

cd dist

.\url2cmd.exe init \
   --name "<自定义 URL 协议名 | name for custom URL scheme>" \
   --powershell \
   --parser "<自定义命令解析器路径 | path for custom command parser>"

start .\insert.reg

卸载

  1. 运行安装目录中的 uninstall.bat 批处理文件
  2. 允许对注册表的更改
  3. 卸载完成

依赖

源码依赖

更改日志

CHANGE LOG

2 操作
shuoying 在 2021-12-01 13:36:01 更新了该帖
shuoying 在 2021-11-28 22:29:47 更新了该帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • 需要使用超链接启用, 试试先使用 win + R 运行 runcmd://PotPlayerMini64.exe 'S:\老师.mp4' /seek=00:10:20.00;pause;

  • 其他回帖
  • buzzingbee

    谢谢分享,不错的小工具。可是本地文件地址很容易变动,所以这个 url 需要更名为 lrl,叫做 本地资源定位符 是不是更准确。

    我也希望看到大家贡献更有趣的用法。

  • dumojun101

    PS d:\Program Files\SiYuan> PotPlayerMini64.exe 'S:\老师.mp4' /seek=00:10:20.00
    界面一闪而过,

    PotPlayerMini64.exe 这个我已经安装,而且也加入电脑的环境变量

  • dumojun101 1 评论

    能否出一个视频教程,安装完,没有办法运行,一闪而过了

    1 回复
    谢谢,已经搞定,重启电脑就行了
    dumojun101