Kumar
Kumar

Reputation: 141

Batch file: Reading registry keys and finding user input exists or not

I am writing a batch file to accept user given string value and need to query the HKLM registry to find whether user given string/key exists or not.

  1. For instance, I need to look at below registry

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs

  2. On my machine, it has got 3 entries beneath the "Microsoft SDKs" viz, .NETFramework Slverlight Windows

  3. If user provides "BlahBlah", I should check the content/list of strings at step 2 and if exists do-something else do-some-other-thing

Can anyone suggest me how to get this please? Please let me know if further explanation is needed.

Regards, Kumar

Upvotes: 1

Views: 240

Answers (2)

npocmaka
npocmaka

Reputation: 57252

@echo off

set /p search_for=what you want to check?

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs" 2>nul|findstr /i /e "%search_for%" 1>nul 2>nul && (
  echo %search_for% does  exist
  rem color will set errorlevel to 0 to prevent the negative execution
  color
) || (
  echo %search_for% does NOT exist
)

Have on mind that Windows XP HE does not have REG command

Upvotes: 1

Alexander P
Alexander P

Reputation: 71

Probably you need to use PowerShell for that. Here is an example: Working with Registry Entries

Upvotes: 0

Related Questions