title: CMD / Batch / Registry - String replace not working as expected?
body: <p>I'm having the most fun trying to replace a substring in one line of code for a windows registry key</p>
  
  <pre><code>[HKEY_CLASSES_ROOT\PING\shell\open\command]
  @="C:\\Windows\\System32\\ping.exe %1 -t"
  </code></pre>
  
  <p><strong>Scenario and Context:</strong></p>
  
  <p>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 <code>ping://</code> from the uri that gets passed as <code>%1</code>.
  sure i could use a batch file, but I'd prefer to have it all in one line in the registry</p>
  
  <p><strong>What I've tried:</strong></p>
  
  <p>so far I've tried appending a list of commands with <code>&amp;</code> setting a var and then echoing it..</p>
  
  <p>tried <code>call set remove=ping://</code> <code>&amp;</code> <code>call set mynewvar=%1:%remove=%</code> <code>&amp;</code> <code>ping.exe %mynewvar% -t</code></p>
  
  <p>I've tried expanding the variables a few times using <code>%%</code></p>
  
  <p>Basically I've been getting weird results or the replace not working at all</p>
  
  <p>Not sure what I'm doing wrong? Typing this, I've started to think I'm overlooking the fact its in string var <code>@="..."</code></p>
  
  <p>thanks</p>
  
  <p><strong>Registry Key</strong></p>
  
  <pre><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 var=%1 &amp; call set var=%%var:ping://=%% &amp; ping.exe %var% -t"
  </code></pre>
  
  <p><strong>browser typed in url</strong>
  <code>ping://8.8.8.8</code></p>
  
  <p><strong>cmd prompt output</strong>
  <code>Ping request could not find host ping://8.8.8.8/ar. Please check the name and try again.</code></p>
  
  <p>I notice the <code>ar</code> after the ip is from <code>%var%</code> it appears its using the <code>%v</code> not <code>%var</code></p>