Board logo

标题: [注册表类] 批处理命令reg query 后如何格式化数据? [打印本页]

作者: tiandyoin    时间: 2023-8-26 22:08     标题: 批处理命令reg query 后如何格式化数据?

本帖最后由 tiandyoin 于 2023-8-29 01:07 编辑

reg query 后数据没有格式化,字段间是用4个空格分隔的。但字段里可以有4个空格,还可以有类型关键字等,这就很难区分了。
像下面的查找语句:
  1. >reg query "HKEY_CURRENT_USER\1\Mouse without Borders2"
  2. HKEY_CURRENT_USER\1\Mouse without Borders2
  3.     Mouse without Borders"=    REG_SZ    134    REG_SZ    134    REG_SZ    DATA1"DATA2
  4.     Mouse without Borders"=    REG_SZ    134    REG_SZ    134    REG_SZ    DATA1"DATA2
复制代码
虽然从导出内容上可以较好区分,但是导出的内容也并非能百分百区分,如果是
  1. [HKEY_CURRENT_USER\1\Mouse without Borders2]
  2. "Mouse without Borders\"="="134    REG_SZ    134    REG_SZ    DATA1\"DATA2"
  3. "Mouse without Borders\"=    REG_SZ    134"="134    REG_SZ    DATA1\"DATA2"
复制代码
光看等号来区别,已经行不通。而且对于一个大项,导出的值可以有成千上百个值,要再从其中搜索到有用的值,会非常耗时。
没想到一些简便高效的方法,请教各路大神,在线指导^_^
作者: Five66    时间: 2023-8-27 02:08

我这里好像没有这个键值,不知道字符串截取**行不行
作者: Five66    时间: 2023-8-27 02:09

回复 2# Five66


    啊,big法竟然变成两个*号了,字符串截取big法
作者: tiandyoin    时间: 2023-8-28 21:44

本帖最后由 tiandyoin 于 2023-8-28 21:46 编辑

回复 3# Five66


这个可以无限套娃的
作者: Batcher    时间: 2023-8-28 22:40

回复 1# tiandyoin


    请使用 reg export 命令导出一个xxx.reg文件上传到网盘我试试
作者: tiandyoin    时间: 2023-8-29 00:00

回复 5# Batcher

这是测试代码的内容:
  1. Windows Registry Editor Version 5.00
  2. [HKEY_CURRENT_USER\1]
  3. "testExpandsz"=hex(2):22,00,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,\
  4.   00,68,00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,\
  5.   22,00,00,00
  6. "testHex"=hex:ff,fe,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,\
  7.   00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,00,00
  8. "multiStr"=hex(7):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,00,\
  9.   6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,00,00,4d,\
  10.   00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,47,00,61,00,72,00,\
  11.   61,00,67,00,65,00,20,00,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,\
  12.   00,68,00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,\
  13.   00,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,47,00,61,\
  14.   00,72,00,61,00,67,00,65,00,00,00,30,00,30,00,30,00,30,00,00,00,00,00
  15. "Mouse without Borders    2"=dword:00123123
  16. "string\""=hex(2):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,00,\
  17.   6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,00,00
  18. "testbinary"=hex:4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,00,\
  19.   6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00
  20. "Mouse without Borders QQ"=hex(b):4d,00,6f,00,75,00,73,00
  21. "Mouse without Borders hex big"=hex(5):9f,82,39,2f
  22. "Mouse without Borders rs"=hex(8):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
  23.   00,74,00,68,00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,\
  24.   73,00
  25. "Mouse without Borders rd"=hex(9):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
  26.   00,74,00,68,00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,\
  27.   73,00
  28. "Mouse without Borders rr"=hex(a):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
  29.   00,74,00,68,00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,\
  30.   73,00
  31. "reg none"=hex(0):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,00,\
  32.   6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00
  33. "testco&product"="Microsoft Garage Mouse without Borders"
  34. "!@!%#$%^&*()_-+={}[]|\\;:'\",<>.?/`~^^%1^^^%1^^^^%1!!!!"="Mouse without Borders !!!! %%%"
  35. "Mouse without Borders !!!! %%%"="!@!%#$%^&*()_-+={}[]|\\;:'\",<>.?/`~^^%1^^^%1^^^^%1!!!!"
  36. "test!%"="Microsoft Garage %%% !!!"
  37. "Microsoft Garage %%% !!!\""=";euou%^>"
  38. ";Microsoft Garage %%% !!!\"*"="e=uou%^>;"
  39. [HKEY_CURRENT_USER\1\Mouse without Borders HKLM]
  40. [HKEY_CURRENT_USER\1\Mouse without Borders2]
  41. "testExpandsz"=hex(2):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,\
  42.   00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,00,00
  43. "testHex"=hex:ff,fe,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,00,74,00,68,\
  44.   00,6f,00,75,00,74,00,20,00,42,00,6f,00,72,00,64,00,65,00,72,00,73,00,00,00
  45. "Mouse without Borders    REG_SZ    134"="134    REG_SZ    DATA"
复制代码

作者: tiandyoin    时间: 2023-8-29 00:02

本帖最后由 tiandyoin 于 2023-8-29 00:15 编辑

回复 3# Five66
  1. :test行尾注释
  2. setlocal EnableDelayedExpansion
  3. @rem  10    0x0a           <Line Feed>          换行符    调用方式: !$0a!
  4. set $0a=^
  5. @rem  10    0x0a           <Line Feed>          使用 ANSI 编码时,以上必须空两行,必须延迟取值 !$0a!
  6. echo hello & rem abc
  7. @rem 字面  ;Microsoft Garage %%% !!!"*"    REG_SZ    e=uo"u%>;
  8. set "line1=;Microsoft Garage %%%%%% ^!^!^!"*"    REG_SZ    e=uo"u%%^^^>;"
  9. set line1
  10. call set "line2=%%line1:    REG_="!$0a!%%"
  11. set line2
  12. @goto :EOF
复制代码
这是我的极限了,可以避免特殊字符转义,结果为注册表值,然后通过查询该值是否存在,进一步验证正确。

另一种方法是行尾注释,但字面字符串并不能转换成命令:
  1. set "line2=!line1:    REG_=" & rem !"
复制代码

作者: Five66    时间: 2023-8-29 00:02

回复 4# tiandyoin


    试试将输出重定向到文本文件,然后在打开来看看
作者: tiandyoin    时间: 2023-8-29 00:05

回复 [url=http:www.bathome.net/redirect.php?got ... 3013&ptid=67146]8#[/url] Five66


    1。 耗时可能几十分钟
    2。有些导出已变成 hex(2):01,02,03 这样的形式
作者: Five66    时间: 2023-8-29 01:06

本帖最后由 Five66 于 2023-8-29 01:58 编辑

回复 9# tiandyoin


    啊,这只能在reg query命令最后面加个/z选项大致区分一下了
还有不介意的话可以使用powershell
作者: tiandyoin    时间: 2023-8-29 09:22

回复 10# Five66
  1.    
  2. REM 不带 /Z
  3.     Mouse without Borders"=    REG_SZ (1)    134    REG_SZ    134    REG_SZ (1)    DATA1"DATA2
  4. REM 带 /z
  5.     Mouse without Borders"=    REG_SZ (1)    134    REG_SZ (1)    134    REG_SZ (1)    DATA1"DATA2
复制代码
两次query 确实不一样,但不清楚两次 query 的结果排列顺序是否一致。
作者: Five66    时间: 2023-8-29 16:13

回复 11# tiandyoin


    两次query之间注册表不变动,顺序应该都是一样的.
像这样有特殊字符或特殊字段的,用批处理来处理起来真的很麻烦,而且也不一定准确(除非能像dir /b那样得到键值名称)




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2