The following script demonstrates how to query registry to check if specific registry key exists. If it does, it checks the value and if doesn’t match required it will remove and recreate with proper value.
————————————————————————————————–
@echo OFF
REM Checks if registry key exists -> If Exists and not equals
REM to something -> change to something
REM Created: Dec 08, 2009
REM Author: Naz Snidanko
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_USERS\.DEFAULT\Control Panel\International"
set VALUE_NAME="sShortDate"
set SerVal=M/d/yyyy
REG QUERY %KEY_NAME% /v %VALUE_NAME%
if %errorlevel% EQU 0 goto Rexist
if %errorlevel% EQU 1 goto NotExist1
:NotExist1
echo Its not here!
goto :DoNe
:Rexist
echo Its Here!
FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
IF %ValueValue% NEQ %SerVal% GOTO Change
goto DoNe
:Change
REG DELETE %KEY_NAME% /v %VALUE_NAME% /f
REG ADD %KEY_NAME% /v %VALUE_NAME% /t REG_SZ /d %SerVal% /f
goto DoNe
:doNe
————————————————————————————————
Hope it helps!
Hey, can you tell me, how can I change the winlogon shell value “explorer.exe” to other with one click, I mean with command or other batch progarm.
Plz, give the script..
Plz..plz… I badly need that….
Plz, give me a reply ASAP…!!
Hi Masum,
I dont have XP system around to test it.
Just replace variables in my script with the following:
set KEY_NAME=”HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon”
set VALUE_NAME=”Shell”
set SerVal=explorer.exe
Don’t forget to test it before deploying live.
How can I modify this to search for multiple registry keys and change the value?
You simply need to define additional variable for another registry keys:
set KEY_NAME2
set VALUE_NAME2
set SerVal2
and use this loop to check
FOR /F “usebackq skip=4 tokens=1-3” %%A IN (`REG QUERY %KEY_NAME2% /v %VALUE_NAME2% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
IF %ValueValue% NEQ %SerVal2% GOTO Change