Question

Can some one please explain what this batch file does?

For /F "eol=E tokens=* delims=" %%A in ('REG QUERY HKLM\SOFTWARE\Classes\CLSID /t REG_BINARY /v data /s') Do (
Set Var=%%A)
REG DELETE %Var% /f
pause

Thank you!

Was it helpful?

Solution

For /F is used to loop through the contents of a file or the output of a command; in this case, the latter. It will loop through the output of the command:

REG QUERY HKLM\SOFTWARE\Classes\CLSID /t REG_BINARY /v data /s

If you look at the for command help (for /?), you will find the following under the section for the /F switch:

eol=c           - specifies an end of line comment character
                  (just one)
delims=xxx      - specifies a delimiter set.  This replaces the
                  default delimiter set of space and tab.
tokens=x,y,m-n  - specifies which tokens from each line are to
                  be passed to the for body for each iteration.
                  This will cause additional variable names to
                  be allocated.  The m-n form is a range,
                  specifying the mth through the nth tokens.  If
                  the last character in the tokens= string is an
                  asterisk, then an additional variable is
                  allocated and receives the remaining text on
                  the line after the last token parsed.
...

Setting the number of tokens is arguably irrelevant for your example (though not harmful), due to the fact that the deliminator value is null.

For each loop your script sets the value of the variable %Var% to %%A which is a temporary variable used by the for loop to store the output. I'm assuming that the command in the for loop will output the name of a registry key, and so %Var% will be set to that name.

The command REG DELETE %Var% /f will delete the Registry entry. The /f switch in this case will force the deletion without prompt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top