I need to check if registry value exists from within .bat ('batch') file, and it seem to be quite hard to do - not many ideas on it I have found. Maybe you can help?

I believe I should use the reg.exe programm to do this but what syntax should I use?

Recommended Answers

All 3 Replies

Here you go. google will find other links too

@echo off
reg query RootKeyName\Path\To\Key\To\Query /v KeyName || echo Does not Exist!!!!

I think that should work. I don't know off hand what the ERRORLEVEL output of this command is if it does not find the KeyName. That should be easy enough to figure out though. ;)

BTW, this could easily be a one liner by doing this:

@echo off && reg query RootKeyName\Path\To\Key\To\Query /v KeyName || echo Does not Exist!!!!

Back to lurking... =8)

@echo off
reg query RootKeyName\Path\To\Key\To\Query /v KeyName || echo Does not Exist!!!!

I think that should work. I don't know off hand what the ERRORLEVEL output of this command is if it does not find the KeyName. That should be easy enough to figure out though. ;)

BTW, this could easily be a one liner by doing this:

@echo off && reg query RootKeyName\Path\To\Key\To\Query /v KeyName || echo Does not Exist!!!!

Back to lurking... =8)

This helped me a lot, as I wasn't entirely certain how to go about an issue I was having. In the end, I used the same way to do a check for a registry entry in a logon script, where the key would be made, if it didn't already exist.

This is for enabling the SDL (Secure Domain Logon) on the Checkpoint client - works like a charm.

REG QUERY HKLM\Software\CheckPoint\SecuRemote /v SDLEnabled || REG ADD HKLM\Software\CheckPoint\SecuRemote /v SDLEnabled /t REG_DWORD /d 1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.