CMD / Batch / Registry - String replace not working as expected?

后端 未结 2 1329
礼貌的吻别
礼貌的吻别 2021-01-18 12:08

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:\         


        
相关标签:
2条回答
  • 2021-01-18 12:15

    Got it.. %v is actually

    %v – For verbs that are none implies all. If there is no parameter passed this is the working directory.

    got that from this answer

    Working 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"
    
    0 讨论(0)
  • 2021-01-18 12:28

    String replace is only possible with variables not with parameters like %1.

    Something like this could be a starting point

    set "var=%1" & call var=%%var:ping://=%%
    

    In the registry it could look like

    ...
    [HKEY_CLASSES_ROOT\PING\shell\open\command]
    @="cmd /k ( set \"var=%1\" & call set var=%%var:ping://=%% & call set var=%%var:/=%% & call ping.exe %%var%% -t)"
    
    0 讨论(0)
提交回复
热议问题