Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to figure out why my reg import command is not working in the script below. 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. 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. Below is the code.

@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
share|improve this question
    
Manually importing origReg.txt (which you just exported) is fine, but is newkeys.reg being created properly? Can you import that from the command line? Also, any errors? –  Karan Jan 23 '13 at 17:30
    
Yes, I'm able to import the new created file(newkey.reg) manually without issue from command line. To test, simple comment out del /q newkeys.reg origReg.txt and the file would be left undeleted for you to import manually. –  powerhouse Jan 24 '13 at 18:26
    
Weird. And there's no error at all? –  Karan Jan 24 '13 at 18:31
    
This is a sample output I get when I run it: "Updating registry values, please wait..." The operation completed successfully. The operation completed successfully. The syntax of the command is incorrect. As you see the last line complains about another command but not sure why it's trying to run another one.....this happens when I run it using just one registry path. With one it seems to work properly, even with that last error massage there. i'm playing with pausing "ping 1.1.1.1 -n 5 > null" to see maybe it's doing too fast that it fails. –  powerhouse Jan 24 '13 at 19:01

1 Answer 1

By adding in

ping 1.1.1.1 -n 5 > null

I was able to pause a bit while the file is being written to disk.....this solved my problem

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.