找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 16985|回复: 8

[注册表类] 执行包含变量的命令时,忘记变量中有特殊字符,导致出错。

[复制链接]
发表于 2008-11-6 17:25:51 | 显示全部楼层 |阅读模式
(本帖原题为“提取应用程序相关注册表数据的P出错?”)
我也不明白是哪错了,所以标题模糊。请管理员手下留情,等明白原因后我会改标题的。
代码如下:
  1. @echo off
  2. (REG QUERY hku /s|find/i "chrome"
  3. REG QUERY hklm /s|find/i "chrome"
  4. REG QUERY hkcc /s|find/i "chrome"
  5. REG QUERY hkcu /s|find/i "chrome"
  6. REG QUERY hkcr /s|find/i "chrome")>reg.lst
  7. setlocal enabledelayedexpansion
  8. for /f "delims=" %%a in (reg.lst) do (
  9. echo %%a|find/i "HKEY_"
  10. echo !errorlevel!
  11. if !errorlevel!==0 (
  12.   REG export "%%a" tmp.reg
  13.   type tmp.reg>>chrome.reg
  14. )
  15. )
  16. pause
复制代码
这是出错情况(已去除@echo off)(这只是一部分):
  1. C:\Documents and Settings\Administrator\桌面>(
  2. echo     <没有名称>     REGC:\Documents and Settings\Administrator\Local Setting
  3. s\Application Data\Google\Chrome\Application\chrome.exe,0  | find "HKEY_"
  4. echo !errorlevel!
  5. if !errorlevel! == 0 (
  6. REG export "    <没有名称>      REGC:\Documents and Settings\Administrator\Local
  7. Settings\Application Data\Google\Chrome\Application\chrome.exe,0" tmp.reg
  8. type tmp.reg 1>>chrome.reg
  9. )
  10. )
  11. 系统找不到指定的文件。
  12. 1

  13. C:\Documents and Settings\Administrator\桌面>(
  14. echo     <没有名称>     REG"C:\Documents and Settings\Administrator\Local Settin
  15. gs\Application Data\Google\Chrome\Application\chrome.exe" "%1"  | find "HKEY_"

  16. echo !errorlevel!
  17. if !errorlevel! == 0 (
  18. REG export "    <没有名称>      REG"C:\Documents and Settings\Administrator\Loca
  19. l Settings\Application Data\Google\Chrome\Application\chrome.exe" "%1"" tmp.reg

  20. type tmp.reg 1>>chrome.reg
  21. )
  22. )
  23. 系统找不到指定的文件。
  24. 1

  25. C:\Documents and Settings\Administrator\桌面>(
  26. echo     <没有名称>     REGC:\Documents and Settings\Administrator\Local Setting
  27. s\Application Data\Google\Chrome\Application\chrome.exe,0  | find "HKEY_"
  28. echo !errorlevel!
  29. if !errorlevel! == 0 (
  30. REG export "    <没有名称>      REGC:\Documents and Settings\Administrator\Local
  31. Settings\Application Data\Google\Chrome\Application\chrome.exe,0" tmp.reg
  32. type tmp.reg 1>>chrome.reg
  33. )
  34. )
  35. 系统找不到指定的文件。
  36. 1

  37. C:\Documents and Settings\Administrator\桌面>(
  38. echo     <没有名称>     REG"C:\Documents and Settings\Administrator\Local Settin
  39. gs\Application Data\Google\Chrome\Application\chrome.exe" "%1"  | find "HKEY_"

  40. echo !errorlevel!
  41. if !errorlevel! == 0 (
  42. REG export "    <没有名称>      REG"C:\Documents and Settings\Administrator\Loca
  43. l Settings\Application Data\Google\Chrome\Application\chrome.exe" "%1"" tmp.reg

  44. type tmp.reg 1>>chrome.reg
  45. )
  46. )
  47. 系统找不到指定的文件。
  48. 1
复制代码
劳驾各位帮我看看,谢谢!


***********************************************************************************************************************************************************************************************************************
改正了一下下:
REG QUERY hklr /s|find/i "chrome")>reg.lst
这句中的hklr改正为hkcr。

[ 本帖最后由 Cameron 于 2008-11-6 20:05 编辑 ]
发表于 2008-11-6 18:09:34 | 显示全部楼层
自己先找找原因:
REG export "    <没有名称>      REGC:\Documents and Settings\Administrator\Local
Settings\Application Data\Google\Chrome\Application\chrome.exe,0" tmp.reg是否生成了tmp.reg?生成的tmp.reg存放在那个路径下?
 楼主| 发表于 2008-11-6 18:29:07 | 显示全部楼层
因为有
  1. if !errorlevel!==0
复制代码
这句,如果%%a为“    <没有名称>     REGC:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\Application\chrome.exe,0” 时find/i找不到“HKEY_”,下面的语句应该不会被执行的,就不会执行type tmp.reg 1>>chrome.reg。应该与tmp.reg无关吧。

[ 本帖最后由 Cameron 于 2008-11-6 18:30 编辑 ]
发表于 2008-11-6 18:57:52 | 显示全部楼层
reg query生成的reg.lst在当前目录下么?
系统找不到指定的文件,是不是因为echo命令中的特殊符号<和>呢?

[ 本帖最后由 Batcher 于 2008-11-6 19:00 编辑 ]
发表于 2008-11-6 19:20:11 | 显示全部楼层
你要查找的其实是含有的chrome的项或子项吧。
因为你的注册表中找不到含有chrome的字符串,根据你的输出看这个P只是找到了一些键值的数据而已。
而reg export 只能导出项或子项,所以导致失败。

另:find /i "chrome"可简化成一个。

======================================
改正,测试了一下,确实如 4 楼所说,是echo < 是没有找到 “没有名称” 这样一个文件。

[ 本帖最后由 wxcute 于 2008-11-6 19:29 编辑 ]
 楼主| 发表于 2008-11-6 19:42:51 | 显示全部楼层

回复 4楼 的帖子

4楼正解!
例子:
  1. C:\Documents and Settings\Administrator\桌面>echo    <ddd>      ddf
  2. 系统找不到指定的文件。

  3. C:\Documents and Settings\Administrator\桌面>echo %errorlevel%
  4. 0
复制代码
reg.lst在当前目录。
这个错误不会对P程序的功能产生影响吧?
如果没影响直接屏蔽输出就。
 楼主| 发表于 2008-11-6 19:50:04 | 显示全部楼层

回复 5楼 的帖子

抱歉,没刷新,没看到你的帖子。
我已经安装了chrome。
另外请问:“另:find /i "chrome"可简化成一个。”是指哪个find /i "chrome",如何简化?
谢谢!
发表于 2008-11-7 17:10:10 | 显示全部楼层

回 7 楼

  1. (REG QUERY hku /s
  2. REG QUERY hklm /s
  3. REG QUERY hkcc /s
  4. REG QUERY hkcu /s
  5. REG QUERY hkcr /s)|find/i "chrome">reg.lst
复制代码
 楼主| 发表于 2008-11-7 17:22:17 | 显示全部楼层

回复 8楼 的帖子

噢,是这儿啊!
真是精益求精!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 16:39 , Processed in 0.010692 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表