2014-02-16 61 views
0

有人可以解释一下这个批处理文件的作用吗?解释下面的批处理文件

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 

谢谢!

回答

2

For /F用于遍历文件的内容或命令的输出;在这种情况下,后者。它会遍历命令的输出:

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

如果你看一下的命令的帮助(for /?),你会发现下段以下的/F开关:

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. 
... 

设置由于分隔符值为空的事实,令牌的数量可能与您的示例无关(尽管无害)。

对于每个循环,您的脚本将变量%Var%的值设置为%%A,这是for循环用于存储输出的临时变量。我假设for循环中的命令将输出注册表项的名称,因此%Var%将设置为该名称。

命令REG DELETE %Var% /f将删除注册表项。在这种情况下,/f开关将强制删除而不提示。

+0

我的理解是该脚本删除所有CLSID键中的所有二进制值。它是否正确? –

+2

它只会删除与查询匹配的最后一个。在'reg delete'命令之前放置一个'echo'并运行它以查看它打印到控制台的内容。 – foxidrive