Rez. Posted February 15, 2014 Posted February 15, 2014 Hi. I'm trying to write a batch script that checks to see if previously imported Registry settings succeeded. Here is the code I have so far:@echo offtitle %~nx0echo.SETLOCAL enabledelayedexpansionFOR %%I IN (HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced) DO (FOR %%J IN (HideIcons SharingWizardOn) DO (FOR /F "tokens=3 delims= " %%K IN ('reg query %%I /v %%J') DO (IF !ERRORLEVEL! EQU 0 (echo successful) ELSE (echo Error)))))PAUSEEXIT The second parameter in the second loop is there by design. I wanted the script to be able to handle missing keys. The ERRORLEVEL portion works fine when the key exists and is set to 0, allowing the IF statement to do it's thing. When it hits a non existent key, Reg Query spits out an error as you would expect but the ERRORLEVEL is not set. I know this because I placed an ECHO command between the second loop and the IF statement and it just gets ignored on the second iteration. The IF statement is not executed at all. I've tried various different things. I've used IF ERRORLEVEL 0, IF !ERRORLEVEL! EQU 1/0 ... etc. Every combination I could think of. I've checked the reg query command on it's own and it seems to set the Errorlevels correctly outside a loop. 0 for success and 1 for a fail. Can anyone tell me what I'm doing wrong? Or atleast point me in the right direction. I've been reading for two days now and am no closer to the answer. Thanks for reading.Here is a screenshot of the script being executed:
submix8c Posted February 15, 2014 Posted February 15, 2014 (edited) Does this help?http://blogs.msdn.com/b/oldnewthing/archive/2008/09/26/8965755.aspxMore than likely this is more useful info?http://www.robvanderwoude.com/errorlevel.php Edited February 15, 2014 by submix8c
Yzöwl Posted February 15, 2014 Posted February 15, 2014 Please try to expand upon your intentions because they currently appear incomplete or confused.I would suggest that those two values would return only a 1 or a 0, if you have set them both previously to their non default value then that should be all you need to check. That said, even if they are already set to their non-default values, where would the harm be in forcing that data again?As a side note please bear in mind that changes to this key, especially if part of an unattended setup will not generally take effect unless run at first logon or later.Also depending upon your Operating System, different versions of reg.exe have different features.The following example would work from Vista but not in Windows XP:@ECHO OFFSETLOCAL(SET RKEY=HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\ADVANCED)(SET VALS=HideIcons SharingWizardOn)FOR %%A IN (%VALS%) DO ( REG QUERY %RKEY% /F %%A /V /E >NUL 2>&1 &&(ECHO=%%A EXISTS)||( ECHO=%%A NOT FOUND))PAUSE
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now