本帖最后由 mengqy 于 2015-3-12 09:53 编辑
公司系统是Xp,Sp2和Sp3,使用老式Outlook Express。
现在需要批量统一更换OE的smtp服务器和pop服务器。
经查询,OE的配置保存在注册表里,每个OE帐号对应一个路径。假如一台电脑有4个账户,则配置文件分别保存在以下路径:
HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000001
HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000002
HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000003
HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000004
……
每个路径下有多个键,但是只需要修改其中的“Pop Server”键和“SMTP Server”键。
请求高手帮忙,实现批量查询和修改功能。
我自己写了两个:
第一个,BUG是第一个00000001可以判断是否相同,但是00000002就不行了。无论00000002是否相同,都进行替换。
(设置的是,如果相同,则替换,如果不同,则忽略)以下是程序:- @echo off
- :begin
- cls
- Set "regpath1=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000001"
- Set "regpath2=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000002"
- Set "regpath3=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000003"
- Set "regpath4=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000004"
- Set "regpath5=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000005"
- Set "findstr1=POP3 Server"
- Set "findstr2=SMTP Server"
- Set "popold=mail.imoke.org"
- Set "popnew=pop.imoke.org"
- Set "smtpold=mail.imoke.org"
- Set "smtpnew=smtp.imoke.org"
- reg query "%regpath1%" /v "%findstr1%" | findstr /i "%findstr1%"
- reg query "%regpath1%" /v "%findstr2%" | findstr /i "%findstr2%"
- reg query "%regpath2%" /v "%findstr1%" | findstr /i "%findstr1%"
- reg query "%regpath2%" /v "%findstr2%" | findstr /i "%findstr2%"
-
- :search1
- echo 搜索1
- for /f "tokens=1* delims=_" %%1 in ('reg query "%regpath1%" /v "%findstr1%" ^| findstr /i "%findstr1%"') do for /f "tokens=1*" %%3 in ("%%~2")do Set "a=%%4"
- echo %a%
- if "%a%"=="%popold%" (
- Set "regpath=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000001"
- goto do
- else (goto search2)
- )
-
- :search2
- echo 搜索2
- for /f "tokens=1* delims=_" %%1 in ('reg query "%regpath2%" /v "%findstr1%" ^| findstr /i "%findstr1%"') do for /f "tokens=1*" %%3 in ("%%~2")do Set "a=%%4"
- echo %a%
- if "%a%"=="%popold%" (
- Set "regpath=HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000002"
- goto do
- else (goto search1)
- )
-
- ::替换过程
- :do
- echo %regpath%
- pause
- echo.
- echo 执行修改
- reg add "%regpath%" /v "%findstr1%" /t REG_SZ /d %popnew% /f
- reg add "%regpath%" /v "%findstr2%" /t REG_SZ /d %smtpnew% /f
- reg query "%regpath%" /v "%findstr1%" | findstr /i "%findstr1%"
- reg query "%regpath%" /v "%findstr2%" | findstr /i "%findstr2%"
- pause>nul
- goto over
-
- :over
- echo 处理完成
- pause>nul
- goto begin
复制代码 在第一个基础上,我想尝试使用for循环出路径,但是在for循环体内,好多函数都不可用,比如说if exist和reg add。
请求论坛高手帮忙解决一下,谢谢。
程序2- @echo off
- setlocal enabledelayedexpansion
- :begin
- ::定义注册表路径循环
- for /l %%a in (3,1,3) do (
- Set "regpath=HKCU\Software\Microsoft\Internet Account Manager\Accounts\0000000%%a"
- echo regpath=!regpath!
-
- ::查找定义
- Set "findstr1=POP3 Server"
- Set "findstr2=SMTP Server"
- Set "find1=mail.imoke.org"
- Set "find2=mx8.dns.com.cn"
- Set "newpop=pop.imoke.org"
- Set "newsmtp=smtp.imoke.org"
- cls
- echo 搜索%%a
- echo !regpath!
- for /f "tokens=1* delims=_" %%1 in ('reg query "!regpath!" /v "!findstr1!" ^| findstr /i "!findstr1!"') do for /f "tokens=1*" %%3 in ("%%~2")do Set "a=%%4"
- echo a=!a!
- echo find=!find1!
- ::如果相同则替换
- if "!a!"=="!find1!" (
- echo 相同
- Set "path=!regpath!"
- echo !path!
- do reg add "!regpath!" /v "!findstr1!" /t REG_SZ /d %newpop% /f
- do reg add "!regpath!" /v "!findstr2!" /t REG_SZ /d %newsmtp% /f
- pause
- else ( pause>nul )
- )
-
- )
-
- ::main
- ::cls
- ::reg query "%regpath%" /v "%find1%" | findstr /i "%find1%"
- ::reg query "%regpath%" /v "%find2%" | findstr /i "%find2%"
-
- pause>nul
- goto begin
复制代码
|