标题: [注册表类] 批处理命令reg query 后如何格式化数据? [打印本页]
作者: tiandyoin 时间: 2023-8-26 22:08 标题: 批处理命令reg query 后如何格式化数据?
本帖最后由 tiandyoin 于 2023-8-29 01:07 编辑
reg query 后数据没有格式化,字段间是用4个空格分隔的。但字段里可以有4个空格,还可以有类型关键字等,这就很难区分了。
像下面的查找语句:- >reg query "HKEY_CURRENT_USER\1\Mouse without Borders2"
-
- HKEY_CURRENT_USER\1\Mouse without Borders2
- Mouse without Borders"= REG_SZ 134 REG_SZ 134 REG_SZ DATA1"DATA2
- Mouse without Borders"= REG_SZ 134 REG_SZ 134 REG_SZ DATA1"DATA2
复制代码
虽然从导出内容上可以较好区分,但是导出的内容也并非能百分百区分,如果是- [HKEY_CURRENT_USER\1\Mouse without Borders2]
- "Mouse without Borders\"="="134 REG_SZ 134 REG_SZ DATA1\"DATA2"
- "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
这是测试代码的内容:- Windows Registry Editor Version 5.00
-
- [HKEY_CURRENT_USER\1]
- "testExpandsz"=hex(2):22,00,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,\
- 22,00,00,00
- "testHex"=hex:ff,fe,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,00,00
- "multiStr"=hex(7):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,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,00,72,00,\
- 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,\
- 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,\
- 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,\
- 00,72,00,61,00,67,00,65,00,00,00,30,00,30,00,30,00,30,00,00,00,00,00
- "Mouse without Borders 2"=dword:00123123
- "string\""=hex(2):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,00,00
- "testbinary"=hex:4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00
- "Mouse without Borders QQ"=hex(b):4d,00,6f,00,75,00,73,00
- "Mouse without Borders hex big"=hex(5):9f,82,39,2f
- "Mouse without Borders rs"=hex(8):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
- 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,\
- 73,00
- "Mouse without Borders rd"=hex(9):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
- 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,\
- 73,00
- "Mouse without Borders rr"=hex(a):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,\
- 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,\
- 73,00
- "reg none"=hex(0):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00
- "testco&product"="Microsoft Garage Mouse without Borders"
- "!@!%#$%^&*()_-+={}[]|\\;:'\",<>.?/`~^^%1^^^%1^^^^%1!!!!"="Mouse without Borders !!!! %%%"
- "Mouse without Borders !!!! %%%"="!@!%#$%^&*()_-+={}[]|\\;:'\",<>.?/`~^^%1^^^%1^^^^%1!!!!"
- "test!%"="Microsoft Garage %%% !!!"
- "Microsoft Garage %%% !!!\""=";euou%^>"
- ";Microsoft Garage %%% !!!\"*"="e=uou%^>;"
-
- [HKEY_CURRENT_USER\1\Mouse without Borders HKLM]
-
- [HKEY_CURRENT_USER\1\Mouse without Borders2]
- "testExpandsz"=hex(2):4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,00,00
- "testHex"=hex:ff,fe,4d,00,6f,00,75,00,73,00,65,00,20,00,77,00,69,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,73,00,00,00
- "Mouse without Borders REG_SZ 134"="134 REG_SZ DATA"
复制代码
作者: tiandyoin 时间: 2023-8-29 00:02
本帖最后由 tiandyoin 于 2023-8-29 00:15 编辑
回复 3# Five66 - :test行尾注释
- setlocal EnableDelayedExpansion
- @rem 10 0x0a <Line Feed> 换行符 调用方式: !$0a!
- set $0a=^
-
-
- @rem 10 0x0a <Line Feed> 使用 ANSI 编码时,以上必须空两行,必须延迟取值 !$0a!
- echo hello & rem abc
- @rem 字面 ;Microsoft Garage %%% !!!"*" REG_SZ e=uo"u%>;
- set "line1=;Microsoft Garage %%%%%% ^!^!^!"*" REG_SZ e=uo"u%%^^^>;"
- set line1
- call set "line2=%%line1: REG_="!$0a!%%"
- set line2
- @goto :EOF
复制代码
这是我的极限了,可以避免特殊字符转义,结果为注册表值,然后通过查询该值是否存在,进一步验证正确。
另一种方法是行尾注释,但字面字符串并不能转换成命令:- 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 -
- REM 不带 /Z
- Mouse without Borders"= REG_SZ (1) 134 REG_SZ 134 REG_SZ (1) DATA1"DATA2
- REM 带 /z
- 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://www.bathome.net/) |
Powered by Discuz! 7.2 |