Batch file to modify existing registry data if it exist.

Hello,

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?

Thanks
litogAsked:
Who is Participating?
 
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.

Steve
0
 
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?

Steve

@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
)

0
 
litogAuthor Commented:
Hello,

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.

Thanks
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Daz_1234Commented:
Hi litog

Here's a VBScript version.

Regards,
Daz.

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"
Else
    MsgBox "Did not modify value"
End If

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Thanks for selecting my answer, hope it helped!
0
 
Bill PrewCommented:
==> dragon-it,

1308 to go...

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

steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.