替代未按预期字符串 - CMD /批次/注册表? [英] CMD / Batch / Registry - String replace not working as expected?

查看:258
本文介绍了替代未按预期字符串 - CMD /批次/注册表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最有趣的尝试在code的一条线为Windows注册表项来替换子

I'm having the most fun trying to replace a substring in one line of code for a windows registry key

[HKEY_CLASSES_ROOT\PING\shell\open\command]
@="C:\\Windows\\System32\\ping.exe %1 -t"

情景和上下文:

的背景是一个自定义URL协议,将打开连续平一个shell到一个特定的IP,我想删除协议平:从URI // 这被作为过去了%1
相信我可以用一个批处理文件,但我preFER拥有这一切在一行在注册表

The context is a custom url protocol that will open up a shell with continuous ping to a specific ip and i want to remove the protocol ping:// from the uri that gets passed as %1. sure i could use a batch file, but I'd prefer to have it all in one line in the registry

我已经试过:

到目前为止,我已经试过追加命令的列表,包括&安培; 设置一个变种,然后呼应它。

so far I've tried appending a list of commands with & setting a var and then echoing it..

尝试呼叫设置删除=平:// &安培; 呼叫设置mynewvar = %1:%=删除% &安培; ping.exe的%mynewvar%-t

我试过用扩大变量几次<​​code> %%

I've tried expanding the variables a few times using %%

基本上我已经得到奇怪的结果或更换所有不工作

Basically I've been getting weird results or the replace not working at all

不知道我做错了吗?键入此,我开始觉得我俯瞰实际上它的字符串变种 @ =...

Not sure what I'm doing wrong? Typing this, I've started to think I'm overlooking the fact its in string var @="..."

感谢

注册表键

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\PING]
@="url:ping protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\PING\shell]

[HKEY_CLASSES_ROOT\PING\shell\open]

[HKEY_CLASSES_ROOT\PING\shell\open\command]
@="cmd /k set var=%1 & call set var=%%var:ping://=%% & ping.exe %var% -t"

在浏览器中键入URL
平://8.8.8.8

的命令提示符输出
Ping请求找不到主机平://8.8.8.8/ar。请检查该名称,然后重试。

我注意到 AR 之后,IP从%VAR%它的使用<$ C $出现C>%v 不是%VAR

I notice the ar after the ip is from %var% it appears its using the %v not %var

推荐答案

明白了.. %V 实际

%V - 对于那些没有动词意味着一切。如果没有传递的参数,这是工作目录。

得到了来自这个答案

工作code

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\PING]
@="url:ping protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\PING\shell]

[HKEY_CLASSES_ROOT\PING\shell\open]

[HKEY_CLASSES_ROOT\PING\shell\open\command]
@="cmd /k set myvar=%1 & call set myvar=%%myvar:ping:=%% & call set myvar=%%myvar:/=%% & call ping.exe %%myvar%% -t"

这篇关于替代未按预期字符串 - CMD /批次/注册表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆