:main
@echo off
set result=
echo.
echo 已进入%~f0
echo ==========================================================================
if "%1" EQU "" (
echo HK can't be emtpy.
call:end&goto:eof
)
if "%2" EQU "" (
echo SearchStr can't be emtpy.
call:end&goto:eof
)
if "%3" EQU "" (
echo SearchStr can't be emtpy.
call:end&goto:eof
)
setlocal enabledelayedexpansion
set SearchResultFile=%temp%\%random%.txt
if exist %SearchResultFile% del %SearchResultFile%
set SearchStr=%2
set ReplaceStr=%3
set SearchStr=%SearchStr:\=\\%
set ReplaceStr=%ReplaceStr:\=\\%
if "%4" EQU "-i" ( set gIgnoreCase=-i && set rIgnoreCase= ) else (set gIgnoreCase= && set rIgnoreCase=/c)
set c=:
set d=::
set SearchStr=!SearchStr:%c%=%d%!
set ReplaceStr=!ReplaceStr:%c%=%d%!
gsar -s%SearchStr% -r%ReplaceStr% -o %SearchResultFile% %gIgnoreCase%
set /a n=0
for /f "tokens=1,2,3* delims=`" %%i in (%SearchResultFile%) do (
if "%%j" EQU "" (set key=%%i) else (
if "!key!" NEQ "搜索结束:" (
set data=%%k
if "!data:~-1!" EQU "\" set data=!data!\
set data=!data:"=\"!
if "%%i" EQU "(默认)" (
echo reg add "!key!" /f /ve /t %%j /d "!data!" ...
reg add "!key!" /f /ve /t %%j /d "!data!"
) else (
echo reg add "!key!" /f /v "%%i" /t %%j /d "!data!" ...
reg add "!key!" /f /v "%%i" /t %%j /d "!data!"
)
)
)
)
endlocal&set result=true&call:end&goto:eof