无忧启动论坛

标题: reg2bat 的代码如何改 [打印本页]

作者: freesoft00    时间: 2007-11-20 18:08
标题: reg2bat 的代码如何改
dos联盟的帖子,其中说有一个错误

好像是%life_r%变量部分位置没做好双引号,造成包含空格的目录出错 ,该如何改,我不会,谁知道在那里改。谢谢。原文如下:


看了最近的几个提问 reg2bat 的帖子,觉得写出来还是蛮实用的,昨晚写的,大家测试下

sed用的不好,感觉有很多垃圾代码,望大虾指点

sed下载:http://www.yx127.com/tools/gsed_407x.rar
CODE:  [Copy to clipboard] @echo off
setlocal enabledelayedexpansion
title reg2bat by:vkill

::注意:注册表项中不可有=,项目、名字、数值中不可有"

::config
set "temp=temp_.txt"
set "life_b=bats_.bat"

:test
cls
if not *%1==* (set "life_r=%1") else (
    echo 只支持单文件,多文件请使用*.reg
    set life_r=
    set /p life_r=请把要转化的reg文件拖到本窗口:
    if %life_r%*==* goto test
                                      )

call :000 %life_r%
goto :eof

:000
echo "%~1"|sed "s/\x22$//"|(findstr /E /I ".reg">nul ||(echo sorry要处理的不是reg文件&pause>nul&goto :eof))
if not exist "%~1" (echo sorry要处理reg文件不存在&pause>nul&goto :eof)

::去除.reg的表头和所有空格
if exist %temp%? del /f/q %temp%?
type "%~1"|sed -e "/^REGEDIT4$/d;/^Windows Registry Editor Version 5.00$/d;/^$/d" -e "y/[/#/" |more>%temp%1
cls

::显示错误并自动除错
cd.>%temp%2
sed "/^#HKEY_.*\.*]/d;/^.*=.*$/d" %temp%1|more>%temp%2
findstr . %temp%2>nul ||(copy /y %temp%1 %temp%3>nul &goto start_)
echo .reg文件中有错误,1秒后开始自动除错
ping -n 2 127.1>nul
sed -e "/^#HKEY_.*\.*]/b;/^.*=.*$/b" -e d %temp%1|more>%temp%3
echo 除错完成

:start_
:去除[]",并转换数据类型,可继续添加数据类型
sed -e "s/^#//;s/]$//" -e "s/\x22//g" %temp%3 |sed "s/=/=REG_SZ=/" |sed "s/=REG_SZ=dword:/=REG_DWORD=/;s/=REG_SZ=hex:/=REG_BINARY=/;s/=REG_SZ=hex(7):/=REG_MULTI_SZ=/;s/=REG_SZ=hex(2):/=REG_EXPAND_SZ=/" |sed "s/^[ \t]*//;s/[ \t]*$//" |sed "/^$/d"|more>%temp%4

::写日志
>>%life_b% echo :: %date% %time% 添加

::写reg add
for /f "tokens=1-3 delims==" %%a in (%temp%4) do (
if not *%%b==* (if not !xiang!*==* >>%life_b% echo reg add "!xiang!" /v "%%~a" /t %%~b /d "%%~c" /f) else (set "xiang=%%~a")
                                                    )

if exist %life_b% (
    echo 正在删除%life_b%中的相同行
    ren %life_b% %temp%5
    sed -n "G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P" %temp%5 |more>%life_b%
    echo %life_b%中的相同行删除完成
                  )

del /f/q %temp%?
echo ok %life_r%2bat转换完成,结果保存在了%life_b%文件中,程序1秒后自动退出
ping -n 3 127.1>nul
goto :eof






欢迎光临 无忧启动论坛 (http://wuyou.net/) Powered by Discuz! X3.3