简体   繁体   English

脚本批处理不适用于.bat文件,但如果在命令提示符下编写,则可以使用

[英]Script batch does not work in a .bat file, but works if written in a command prompt

my question is that i have to delete from system registry every key and subkey that contain a specific word (that can change, it itn's always the same word) 我的问题是,我必须从系统注册表中删除每个包含特定单词的键和子键(可以更改,它始终是同一个单词)

until now i have created a script in Batch that export in a .txt file every key and subkey that contain the word i'm searching for, with a vbs script i can modify the name of the key (because the REG QUERY export key like "HKEY_LOCAL_MACHINE" and REG DELETE need only "HKLM", then with another script i need to search every key (or subkey) the QUERY export and delete them. the script is like 到现在为止,我已经批量创建了一个脚本,该脚本以.txt文件导出包含要搜索的单词的每个键和子键,并使用vbs脚本可以修改键的名称(因为REG QUERY导出键类似于“ HKEY_LOCAL_MACHINE”和“ REG DELETE”只需要“ HKLM”,然后使用另一个脚本,我需要搜索QUERY导出的每个键(或子键)并将其删除。

SET /P keyword="insert keyword to search: "
REG EXPORT HKCU HKCU.reg
REG QUERY HKCU /f %Chiavediricerca% /s >logHKCU.txt
cscript replace.vbs "logHKCU.txt" "HKEY_CURRENT_USER" "HKCU"
FOR /F "delims=;" %i in (logHKCU.txt) do REG DELETE "%i" /va /f

now my problem is that if i write every line in a command prompt, the script work greatly, but if i put this code in a .bat file, the script stop when at the FOR command, closing cmd without displaying any error... 现在我的问题是,如果我在命令提示符下写每一行,脚本会很好地工作,但是如果我将此代码放在.bat文件中,则脚本在使用FOR命令时会停止,关闭cmd而不会显示任何错误...

any suggestion? 有什么建议吗? sorry if my english is not perfect, and thank for every help you can give me! 对不起,如果我的英语还不够完善,谢谢您能给我的一切帮助!

In batch scripts you should double the percent signs on variables for the FOR command. 在批处理脚本中,应将FOR命令的变量的百分号加倍。 This is noted in the FOR command help ( for /? at the command prompt): 这在FOR命令帮助中有所说明(在命令提示符下for /? ):

To use the FOR command in a batch program, specify %%variable instead of %variable. 要在批处理程序中使用FOR命令,请指定%% variable而不是%variable。 Variable names are case sensitive, so %i is different from %I. 变量名称区分大小写,因此%i与%I不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM