Batch file to modify existing registry data if it exist.


I'm looking to modify a registry data only if it exist.  For example;

HKCU\Software\Microsoft\Search Assistant\

Value InstallDir
Data   C:\Windows\srchasst\

I'd like to modify C:\Windows\srchasst\ to C:\srchasst but only if that data exist.  Does anyone have any ideas?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
This will check the key to see if it is see to c:\windows\srchasst and if it is then change it to c:\srchasst.  Is that what you wanted?


@echo off
reg query "HKCU\Software\Microsoft\Search Assistant" /v InstallDir | find "C:\WINDOWS\srchasst"

if errorlevel 1 (
  echo key not found
) ELSE (
  echo Key found
  reg add "HKCU\Software\Microsoft\Search Assistant" /v InstallDir /d C:\srchasst /f

litogAuthor Commented:

Thanks, but I was just using the above Data as an example.  I don't want to look at anything on the file system, only in the registry.

Steve KnightIT ConsultancyCommented:
That is in the registry.  It queries one value and runs it through FIND to check if that is the value then sets it if it is not.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Hi litog

Here's a VBScript version.


Set wshShell = CreateObject("WScript.Shell")

strVal = ""

On Error Resume Next
strVal = wshShell.RegRead ("HKCU\Software\Microsoft\Search Assistant\InstallDir")
On Error Goto 0

If LCase(strVal) = "c:\windows\srchasst\" Then
    wshShell.RegWrite "HKCU\Software\Microsoft\Search Assistant\InstallDir", "C:\srchasst", "REG_SZ"
    MsgBox "Modified value"
    MsgBox "Did not modify value"
End If

Open in new window

Steve KnightIT ConsultancyCommented:
Thanks for selecting my answer, hope it helped!
Bill PrewIT / Software Engineering ConsultantCommented:
==> dragon-it,

1308 to go...

Steve KnightIT ConsultancyCommented:
Just 308 I think :-) ...bed calls for few hours, will see what gets cleared over night!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.