Check if key exists

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
OBr
Posts: 2
Joined: 04 Jun 2008 15:57

Check if key exists

#1 Post by OBr » 04 Jun 2008 16:14

Hallo,
I'd like to check whether the key exists.

Code: Select all

REG QUERY HKEY_CLASSES_ROOT\.php >>null
IF ERRORLEVEL 1 ECHO not found

This example works, but prints error and I can't hide it.

I tried it using the FIND in following script.

Code: Select all

REG QUERY "HKEY_CLASSES_ROOT" | FIND /i ".php"
IF ERRORLEVEL 1 ECHO not found

Works for .php but so as .php3, .phps, ... (.php*).

How can I check check whether just a "HKEY_CLASSES_ROOT\.php" exists?

Thank you.

dizze
Posts: 10
Joined: 12 Jul 2006 07:53
Contact:

#2 Post by dizze » 05 Jun 2008 08:31

Hi,

If you want to hide all the output from your first example do:

Code: Select all

reg query HKEY_CLASSES_ROOT\.php 1>nul 2>nul
if errorlevel 1 echo not found


1> redirects stdout
2> redirects stderr which is what the output of reg is in this case.

Dizz-E

OBr
Posts: 2
Joined: 04 Jun 2008 15:57

#3 Post by OBr » 05 Jun 2008 14:24

dizze wrote:1> redirects stdout
2> redirects stderr which is what the output of reg is in this case.

It works.
Thank you.

Post Reply