K
kick
I'm putting together a fairly simply batch file (to be run under XP)
that
-checks for a registry value (REG QUERY)
-if the value doesn't exist, add it (REGEDIT /S or REG ADD /F... tried
both)
-checks for the registry value again (REG QUERY)
-if the value exists now, write entry to success log otherwise, write
entry to failure log
After the calls to REG QUERY i'm just checking %errorlevel% - 0 = the
value exists and 1 (or not 0) = the value doesn't exist.
The first call to REG QUERY returns the correct %errorlevel% -
confirmed by checking the registry manually prior to running the
script. The subsequent call to REG QUERY returns the wrong value for
%errorlevel%. In fact, it returns the same value as what the first
call to REG QUERY returned. Thoughts? Nowhere in my script and I
setting the value of ERRORLEVEL... it's as if the ERRORLEVEL value is
being retained or is "stuck".
My scripts is:
@ECHO OFF
CLS
REG QUERY "HKLM\SOFTWARE\MyKey" /V "MyValue"
IF %ERRORLEVEL% NEQ 0 (
REGEDIT /S My.reg
REG QUERY "HKLM\SOFTWARE\MyKey" /V "MyValue"
IF %ERRORLEVEL% EQU 0 (
ECHO %date%,%time%,%computername% >> success.log
) ELSE (
ECHO %date%,%time%,%computername% >> failure.log
)
)
EXIT
that
-checks for a registry value (REG QUERY)
-if the value doesn't exist, add it (REGEDIT /S or REG ADD /F... tried
both)
-checks for the registry value again (REG QUERY)
-if the value exists now, write entry to success log otherwise, write
entry to failure log
After the calls to REG QUERY i'm just checking %errorlevel% - 0 = the
value exists and 1 (or not 0) = the value doesn't exist.
The first call to REG QUERY returns the correct %errorlevel% -
confirmed by checking the registry manually prior to running the
script. The subsequent call to REG QUERY returns the wrong value for
%errorlevel%. In fact, it returns the same value as what the first
call to REG QUERY returned. Thoughts? Nowhere in my script and I
setting the value of ERRORLEVEL... it's as if the ERRORLEVEL value is
being retained or is "stuck".
My scripts is:
@ECHO OFF
CLS
REG QUERY "HKLM\SOFTWARE\MyKey" /V "MyValue"
IF %ERRORLEVEL% NEQ 0 (
REGEDIT /S My.reg
REG QUERY "HKLM\SOFTWARE\MyKey" /V "MyValue"
IF %ERRORLEVEL% EQU 0 (
ECHO %date%,%time%,%computername% >> success.log
) ELSE (
ECHO %date%,%time%,%computername% >> failure.log
)
)
EXIT