Page 1 of 1

Check if key exists

Posted: 04 Jun 2008 16:14
by OBr
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.

Posted: 05 Jun 2008 08:31
by dizze
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

Posted: 05 Jun 2008 14:24
by OBr
dizze wrote:1> redirects stdout
2> redirects stderr which is what the output of reg is in this case.

It works.
Thank you.