0
我想弄清楚爲什麼我的reg導入命令不能在下面的腳本中工作。 當我從DOS運行reg導入fileName.reg時,它工作正常,但是當它包含在下面的腳本中時,它什麼都不做,我找不到原因。我可以看到導出已正確完成,並且格式對我來說很合適。當我在相同的導出文件上使用reg import命令時,它工作正常。以下是代碼。註冊導入不能在批處理腳本中工作
THX ......
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
REM This script updates the Windows Registry for the
REM update Admin Nodes
set service1Key=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyService1\Parameters
set service2Key=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyService2\Parameters
echo updating [%service1Key%]
call :updateRegKeys %service1Key%
echo updating [%service2Key%]
call :updateRegKeys %service2Key%
SET count=3
set looper=1
FOR /L %%A IN (1,1,%count%) DO (call :updateAllServers %%A)
GOTO:EOF
:updateAllServers
SET domainKey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyDomain%looper%\Parameters
SET otherDomainKey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyOtherDomain%looper%\Parameters
echo [%domainKey%]
echo [%otherDomainKey%]
echo .
call :updateRegKeys %domainKey%
call :updateRegKeys %otherDomainKey%
set /a looper+=1
goto:eof
:updateRegKeys
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
set "registrykey=%1"
set findv="-Xms512m"
set replacev="-Xms512m something that is long"
echo "Updating registry values, please wait..."
REG EXPORT "%registrykey%" origReg.txt
call :findReplace %findv% %replacev% origReg.txt > newkeys.reg
reg import newkeys.reg
del /q newkeys.reg origReg.txt
:findReplace
REM finds and replaces a string
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
轉到:EOF
我能夠在相同的導出文件上手動運行reg導入,所以我非常確定情況並非如此。 – powerhouse