• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to? tokens and delims problem

Nov 3, 2012
Hi guys, this is my CMD batch:

FOR /F tokens^=5^ delims^=\^" %%G IN ('REG QUERY "HKCR\http\shell\open\command" /v ""') DO SET Default=%%G

It works perfectly, but once compiled with Take Command (.btm file), my scripts doesn't work anymore... Have you an idea to correct it? Thanks in advance.
I never use that syntax myself, but isn't the whole TOKENS and DELIMS business supposed to go in double quotes?
That's correct, and documented. But with the documented syntax, you can't use a double-quote as a delimiter. So the OP used the kludge (find it on stackoverflow or superuser)
tokens^=5^ delims^=\^"
which is considered a single argument (as if it were quoted) because all the normal argument separators have been escaped.

I doubt Rex will feel compelled to emulate that behavior. In TCC, do it like this:
v:\> FOR /F "tokens=5 delims=\^q" %G IN ('REG QUERY "HKCR\http\shell\open\command" /v ""') DO echo %G
 -osint -url
... which is correct ... double the quotes on the variable G if you like.
Here's a nice way to do it with TCC.
v:\> echo %@word["\^q",3,%@regquery[HKCR\http\shell\open\command\]]
 -osint -url
(which is correct).
Notice how brief and to-the-point it is ... and that running the external REG.EXE is not necessary.

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
What's the goal? To get the filename of the default web browser?

You can get the default open string with:
echo %@ftype[http]
To grab the first word of that string:
echo %@word[0,%@ftype[http]]
And to strip off the path and get just the filename:
echo %@filename[%@word[0,%@ftype[http]]]
Yup! @FTYPE is a little easier than @REGQUERY.
v:\> echo %@ftype[http]
"l:\Firefox\firefox.exe" -osint -url ""
Once you have that string, you can extract from it whatever information you want. A few examples have been given.
Top Bottom