简体   繁体   English

Reg导入在批处理脚本中不起作用

[英]Reg import does not work in batch script

I'm trying to figure out why my reg import command is not working in the script below. 我试图弄清楚为什么我的reg import命令在下面的脚本中不起作用。 When I run the reg import fileName.reg from the DOS it works fine but when included in the script below it does nothing and I cannot find why. 当我从DOS运行reg import fileName.reg时,它可以正常工作,但是当包含在下面的脚本中时,它什么也不做,我找不到原因。 I can see the export completed correctly and the format looks ok to me. 我可以看到导出正确完成,并且格式对我来说还可以。 When I use the the reg import command on the same exported file it works fine. 当我在相同的导出文件上使用reg import命令时,它可以正常工作。 Below is the code. 下面是代码。

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.
)

goto:eof 转到:eof

You need to 'escape' all backslashes in your *.reg script, eg (notice the '\\\\'): 您需要在* .reg脚本中“转义”所有反斜杠,例如(注意“ \\\\”):

[HKEY_CURRENT_USER\Environment]
"LIB_DIR"="C:\\Libraries"

Otherwise it will not work and you will have absolutely no idea why (no errors, warnings just nothing happens). 否则它将无法正常工作,您将完全不知道为什么(没有错误,警告,什么也没有发生)。 I had this problem some time ago. 我前一段时间有这个问题。

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM