Board logo

标题: 批处理删除XP输入法问题!请dos高手解决 [打印本页]

作者: bsijl     时间: 2006-2-12 01:56    标题: 批处理删除XP输入法问题!请dos高手解决

***********************************************************
echo rip fareast ime
rem 把Unicode编码的intl.inf文件转换为UTF8编码,这样普通的程序可以用类似处理英文的方法来处理
copy i386\intl.inf intl.inf
recode u2..u8 intl.inf
rem  在intl.inf文件中搜索带有[ime]这样的行
findstr /i ^^\[.*ime intl.inf |findstr /i /V \[FE_CONIME\] | findstr /i /V \[EA_IME_SHARED\] >tmp.imerfall.txt
rem 找出所有的和输入法相关的文件名字存入tmp.IMEfiles.txt
for /F "tokens=1,2,3* delims=[]" %%i in ('findstr /i /V LGReg tmp.imerfall.txt') do (
sed -n -e  /^^\[%%i\]/,/^^\[.*\]/p intl.inf | sed -e  /^^\[.*\]/d   -e /^^$/d>>tmp.IMEfiles.txt
)
rem 找出所有和输入法相关的文件名字的注册表项存储为tmp.imeLGReg.txt,略过了英文的输入法的注册报条目
for /F "tokens=1,2,3* delims=[]" %%i in ('findstr /i LGReg tmp.imerfall.txt') do (
sed -n -e  /^^\[%%i\]/,/^^\[.*\]/p intl.inf | sed -e  /^^\[.*\]/d   -e /^^$/d |findstr /V 00000804 |findstr /V 00000404>>tmp.imeLGReg.txt
)
rem 删除intl.inf中和ime相关的注册表项
fgrep -v  -F -f tmp.imeLGReg.txt intl.inf>tmp.intl.inf
rem 删除可能存在的空格
if exist xxx.tmp.txt del /Q xxx.tmp.txt
for /F "eol=; tokens=1* delims=, " %%x in (tmp.imefiles.txt)  do @echo %%x>>xxx.tmp.txt
move /Y xxx.tmp.txt tmp.imefiles.txt

rem 把所有要删除的文件都存到allfilefordel.txt中
type tmp.imefiles.txt>>allfilefordel.txt
rem 从intl.inf删除对这些输入法文件的引用
findstr /V /i /B /G:tmp.imefiles.txt tmp.intl.inf>intl.inf
rem 把intl.inf转换为unicode编码
recode u8..u2/21 intl.inf
rem 覆盖在i386目录的intl.inf文件
move /Y INTL.INF I386\intl.inf
rem 从txtsetup.sif删除对这些输入法文件的引用
findstr /V /i /B /G:tmp.imefiles.txt i386\txtsetup.sif>tmp.txtsetup.sif
move  /Y tmp.txtsetup.sif i386\txtsetup.sif
rem 从dosnet.inf删除对这些输入法文件的引用
findstr /V /i /B /G:tmp.imefiles.txt i386\dosnet.inf>tmp.dosnet.inf
move  /Y tmp.dosnet.inf i386\dosnet.inf
rem  复制HIVESYS.INF文件
copy I386\HIVESYS.INF HIVESYS.INF
rem 把HIVESYS.INF转换为utf8编码
recode u2..u8 HIVESYS.inf
rem 需要删除的注册表项
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0010804">tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0020804">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0030804">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0050804">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E00E0804">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00010409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00010409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00010409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00020409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00020409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00020409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00030409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00030409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00030409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00040409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00040409">>tmp.imereg.lst
echo HKLM,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00040409">>tmp.imereg.lst
rem 从HIVESYS.INF中删除上面的注册表项
findstr /i /v /G:tmp.imereg.lst HIVESYS.INF >tmp.hivesys.inf
move /Y tmp.hivesys.inf  hivesys.inf
rem 把hivesys.inf变换为unicode编码
recode u8..u2/21 hivesys.inf
rem 覆盖i386目录的 hivesys.inf
move /Y HIVESYS.INF I386\HIVESYS.INF
rem 删除临时文件
del tmp.*
***********************************************************
findstr /V /i /B /G:tmp.imefiles.txt i386\dosnet.inf>tmp.dosnet.inf这句从dosnet.inf删除对这些输入法文件的引用不好用啊!tmp.imefiles.txt里是单纯的文件名,dosnet.inf里是文件名前加了个d1,,这样也不能比较啊,不好用!而且我发现dosnet.inf也有问题,可能是编码的问题,我用findstr /v /i /b /G:dosnet.inf dosnet.inf居然出来结果了,是同一个文件啊,一样一样的,怎么会出来结果呢?用recode u2..u8 dosnet.inf也不行,还是一样出现结果!请问这是怎么回事?
附件 1: dosnet.rar (2006-2-12 01:56, 15.02 K, 下载附件所需积分 1点 ,下载次数: 33)

作者: willsort     时间: 2006-2-12 10:48
Re bsijl:

      因为你的 findstr 使用了 /B ,所以文件名与d1+文件名必然因为行首不同而匹配失败,去掉这个开关应该就可以了。

      至于 findstr /v /i /b /G:dosnet.inf dosnet.inf 的结果确实比较奇怪,我测试了一些批处理文件,结果大都与原文不同,而不使用 /b 也会得到不一样的结果,估计是 /G 参数的问题,以前没有注意过这个参数。
作者: bsijl     时间: 2006-2-13 20:06
那就没办法了,实际上这findstr /V /i /B /G:tmp.imefiles.txt i386\dosnet.inf>tmp.dosnet.inf可以不用的,交给NLITE去做就可以了,唉!还有
一个问题就是fgrep删掉条件行后文件变得没有格式了,用FOR删除空格后,文件里的中文会变成乱码!经过试验发现出现这样的情况好像是被处理的文件第一行是空行,删掉这一行后,用FORG再整理格式就没问题了,这是怎么回事?请解答
作者: willsort     时间: 2006-2-13 21:45
Re bsijl:

      fgrep 这个工具没有接触过,不知其中的细节。forg 是否应为 for ?

      至于 for 删除空格出现乱码的问题,我使用你的语句测试过我本地的一些文本文件,没有遇到此问题,只是会删除其中的所有空行,包括行首的空格,这是 for /f 已知的特性。所以我怀疑你的问题与文本的编码方式有关,导致删除空行时影响到下一行,使此后整个文本的编码错位。

      如果你能提供 tmp.imefiles.txt 和 xxx.tmp.txt 两个文件,我判断问题会更有把握。
作者: bsijl     时间: 2006-2-21 16:59
出差几天,刚回来,没想到版主这么细心哟,呵呵,这里先谢过了,forg是应该为for,temp.imefile.txt和xxx.tmp.txt稍后我把它放上来。如果您能精简一下XP就更好了,那样可以更好的查一下这个批处理的问题,原文地址我放上来,您去看看就知道了http://www.blogchinese.com/user1/279/archives/2005/158761.shtml
作者: wua0550     时间: 2007-5-31 15:06
下过来学习下
作者: tider1984     时间: 2007-8-21 13:15
正需要这东西. 谢谢了.
作者: tider1984     时间: 2007-8-21 13:20
下载 的文件有问题,解压缩后,只有一个.inf文件, 请楼主重新弄一下.
作者: zhanghdong     时间: 2010-3-9 00:17
好东西。。终于找到了。谢谢。。
作者: yuan53770     时间: 2010-11-21 00:33
recode命令不太了解