[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[注册表类] [已解决]批处理如何导出注册表指定的项?

本帖最后由 e98123 于 2019-2-28 08:15 编辑

set REGFILE=a.reg
set KEYNAME=HKEY_CURRENT_USER\Environment

echo Windows Registry Editor Version 5.00>%REGFILE%
echo [%KEYNAME%]>>%REGFILE%
reg export "%KEYNAME%" export.bak
type export.bak|find /i """TEMP""">>%REGFILE%

1、以上export.bak导出的内容为:
[HKEY_CURRENT_USER\Environment]
"TEMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,\
  74,00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00
"TMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,\
  45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,74,\
  00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00

2、取TEMP后,在a.reg中只能得到:(只有1行)
"TEMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\

3、请问有什么方法可以完整地得到:(完整3行)
"TEMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,\
  74,00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00


PS:
打算做一个注册表修改的玩意,安装时备份导出原来的设置,卸载时再导入备份时的设置,直接导入注册表REG文件比较方便,不打算使用reg add方法。

测试过的,这样还不行那我也不知道了

TOP

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims==" %%a in (1.txt) do (
   if "%%b" neq "" set regtmp=
   if defined regtmp echo %%a
   if /i %%~a==temp (set "regtmp=."&echo %%a ...
zm900612 发表于 2011-5-29 11:43

只显示了请按任意键继续......

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "tokens=1* delims==" %%a in (1.txt) do (
  4.    if "%%b" neq "" set regtmp=
  5.    if defined regtmp echo %%a
  6.    if /i %%~a==temp (set "regtmp=."&echo %%a=%%b)
  7. )
  8. pause
复制代码

TOP

我有个思路不知行不行得通?

"TEMP"=为起始,"TMP"开头的"为终止,这样的语名应该怎么写呢?

TOP

@echo off
for /f "tokens=1* delims==" %%a in (1.txt) do (
   if /i %%~a==temp set "regtmp=%%b"&echo %%a=%%b
   if defined regtmp if "%%b"=="" (
      echo    %%a
   ) else set regtmp=
)
pause
zm900612 发表于 2011-5-29 10:44


假设1.TXT的内容为:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Environment]
"TEMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,\
  74,00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00
"TMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,\
  45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,74,\
  00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00


贴出的代码运行后无任何返回?

TOP

  1. @echo off
  2. for /f "tokens=1* delims==" %%a in (1.txt) do (
  3.    if /i %%~a==temp set "regtmp=%%b"&echo %%a=%%b
  4.    if defined regtmp if "%%b"=="" (
  5.       echo    %%a
  6.    ) else set regtmp=
  7. )
  8. pause
复制代码

TOP

也许可以参考下前几天的帖子:
http://bbs.bathome.net/thread-12530-1-2.html
zm900612 发表于 2011-5-29 10:18

我现在不是在导出上有问题,而是要取出标签TEMP,的完整多行内容;
"TEMP"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,\
  74,00,69,00,6e,00,67,00,73,00,5c,00,54,00,65,00,6d,00,70,00,00,00

TOP

也许可以参考下前几天的帖子:
http://bbs.bathome.net/thread-12530-1-2.html

TOP

返回列表