Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch file help

Status
Not open for further replies.

melfineo

IS-IT--Management
Feb 19, 2008
83
FR
does my syntax here look right for the find and if errorlevel commands?

reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN > c:\poo.txt
FIND /I "OPEN" C:\poo.txt
if errorlevel 0 goto OPEN1
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"
GOTO END


thanks
 
IF Help (IF /?) said:
IF ERRORLEVEL NUMBER Specifies a true condition if the last program run returned an exit code equal to or greater than the NUMBER specified.

Your if errorlevel 0 will always go to label OPEN1 (which you don't show).
 
okay amended but it still seems to be doing what it was doing before which is just running the first reg query over and over again. Here is the full code. I am trying to add a reg entry based on wheter or not it exists in the first place.


reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN > c:\poo.txt
FIND /I "OPEN" C:\poo.txt
if not errorlevel 1 goto OPEN1
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"
GOTO END

:OPEN1
reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN1 c:\poo.txt
FIND /I "OPEN1" C:\poo.txt
if not errorlevel 1 goto OPEN2
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN1 /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"
GOTO END

:OPEN2
reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN2 > c:\poo.txt
FIND /I "OPEN2" C:\poo.txt
if not errorlevel 1 goto OPEN3
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN2 /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"
GOTO END

:OPEN3
reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN3 > c:\poo.txt
FIND /I "OPEN3" C:\poo.txt
if not errorlevel 1 goto OPEN4
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN3 /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"
GOTO END

:OPEN4
reg query hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN4 > c:\poo.txt
FIND /I "OPEN4" C:\poo.txt
if not errorlevel 1 goto END
REG ADD hkcu\software\microsoft\office\11.0\excel\options\ /v OPEN4 /t REG_SZ /d "C:\Program Files\Microsoft Office\OFFICE11\Library\test.xla"


:END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top