How to determine if a Registry key exists? 
Author Message
 How to determine if a Registry key exists?

I would like to determine if a Registry key exists (I don't want to read
it,
especially since the key has no values associated with it). Specially,
I'm trying to determine if a system has a particular version of an
application installed. The application has a key in the Registry that
indicates the version. For example:

HKLM\SOFTWARE\company\product\6.03

There is no value names or default value associated with the key. I
see a RegRead function, but I get an error, when I try to read this
key.

I've heard a little about this RegObj.dll. Will it do this type of test
for me? Will I have to install this DLL on each machine that I want
to run the script on? (I'd prefer not too).

Thanks in advance,

PCM
P.S. please CC to my e-mail address, so that I can quickly see your
reply.

--------------------+------------------------+-------------------------
Paul Michali        | PHONE/FAX              | PAGER
                    |                        |
Enhanced Services   | (800)-537-8662 x5-3200 | (800)-365-4578 (voice)
Migration Bus. Unit | (603)-665-3200 (direct)| (888)-358-5637 (numeric)
                    |                        |
Cisco Systems, Inc. | EMAIL                  | EMAIL BASED PAGING
25 Sundial Ave.     |                        |

--------------------+------------------------+-------------------------



Sun, 02 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
It doesn't have any explicit KeyExists method but it's easy to write the
equivalent in code...

'================================================
Set oReg = CreateObject("RegObj.Registry")

strKeyName = "\HKEY_CURRENT_USER\MyKey"
MsgBox RegKeyExists(strKeyName)

wscript.quit

Function RegKeyExists(vKeyName)
  On error Resume Next
  Call oReg.RegKeyFromString(vKeyName)
  If Err then
    RegKeyExists = False
  Else
    RegKeyExists = True
  End If
End Function
'================================================

And yes, you'd have to install RegObj.dll on every machine...

Maybe the WSH 2.0 beta 2 will have some improvements in the registry
methods...?

--
Michael Harris


| I would like to determine if a Registry key exists (I don't want to read
| it,
| especially since the key has no values associated with it). Specially,
| I'm trying to determine if a system has a particular version of an
| application installed. The application has a key in the Registry that
| indicates the version. For example:
|
| HKLM\SOFTWARE\company\product\6.03
|
| There is no value names or default value associated with the key. I
| see a RegRead function, but I get an error, when I try to read this
| key.
|
| I've heard a little about this RegObj.dll. Will it do this type of test
| for me? Will I have to install this DLL on each machine that I want
| to run the script on? (I'd prefer not too).
|
| Thanks in advance,
|
| PCM
| P.S. please CC to my e-mail address, so that I can quickly see your
| reply.
|
| --------------------+------------------------+-------------------------
| Paul Michali        | PHONE/FAX              | PAGER
|                     |                        |
| Enhanced Services   | (800)-537-8662 x5-3200 | (800)-365-4578 (voice)
| Migration Bus. Unit | (603)-665-3200 (direct)| (888)-358-5637 (numeric)
|                     |                        |
| Cisco Systems, Inc. | EMAIL                  | EMAIL BASED PAGING
| 25 Sundial Ave.     |                        |

| --------------------+------------------------+-------------------------
|
|



Sun, 02 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
Hi,

you can use the On Error Resume Next construction to test a key's
existence in VBScript. Have a look into my WSH Bazaar at:

http://ourworld.compuserve.com/homepages/Guenter_Born/index0.htm

Click the link to the FAQ page, and have a look into the discussion of
"Error handling in scripts". There is a code sample with a KeyExists
function written in VBScript, which will do the job. In JScript 5.0 you can
use the similar Try Catch technique to do the same. I wrote also an ActiveX
control which provides a KeyExists method (downloadable as WSHExtend
from my WSH Bazaar).

G. Born




Mon, 03 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?

Quote:

> you can use the On Error Resume Next construction to test a key's
> existence in VBscript.

...

Quote:
> In JScript 5.0 you can
> use the similar Try Catch technique to do the same.

In my JScript code, I did a try..catch block, but I was seeing it entering
the catch block for a key that does exist!  Here's the actual keys I'm
trying to access (which you can apply using regedit).

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition]

[HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.00]

[HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.01]

[HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.03]

What I want to do, is see if the last key exists in a user's registry. Note
that each of the last 3 keys are sub keys and none of then have default
values or value names below them.

Here is a fragment of the code...

var hasInstalledDevPartner = false;
try
{
 var DevPartnerKey = "HKLM\\SOFTWARE\\NuMega\\BoundsChecker Visual C++
Edition\\6.03\\";
 var devPartnerVersion = WSHShell.RegRead(DevPartnerKey);

  hasInstalledDevPartner = true;

Quote:
}

catch (e)
{
 // Unable to read registry key
 //WScript.Echo("Problem: NuMega DevPartner 6.03 is not installed. Error: " +
e);

Quote:
}

It seems like catching the error doesn't work for sub keys that are
empty. I've tried both with and without the trailing backslash on the
registry key.

Any ideas? I'd rather not have to distribute a DLL and have everyone
install the DLL and then run the script (heck, I'd might as well write
a C++ or Java app, if I have to go that far... :^)

PCM

--------------------+------------------------+-------------------------
Paul Michali        | PHONE/FAX              | PAGER
                    |                        |
Enhanced Services   | (800)-537-8662 x5-3200 | (800)-365-4578 (voice)
Migration Bus. Unit | (603)-665-3200 (direct)| (888)-358-5637 (numeric)
                    |                        |
Cisco Systems, Inc. | EMAIL                  | EMAIL BASED PAGING
25 Sundial Ave.     |                        |

--------------------+------------------------+-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
Someone (Jeff Mastry, I believe) posted a slick workaround that worked
something like this...

Try to write a dummy named value to the key (with error trapping enabled),
using an arbitrary value name that you _know_ can't possibly exist (like
MyDogsNameIs = "Fido").

If the RegWrite of the dummy named value fails, then the parent key doesn't
exist.

If it succeeds, it exists, so delete the dummy named value.

--
Michael Harris


|
| >
| > you can use the On Error Resume Next construction to test a key's
| > existence in VBscript.
|
| ...
|
| > In JScript 5.0 you can
| > use the similar Try Catch technique to do the same.
|
| In my JScript code, I did a try..catch block, but I was seeing it entering
| the catch block for a key that does exist!  Here's the actual keys I'm
| trying to access (which you can apply using regedit).
|
| REGEDIT4
|
| [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition]
|
| [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.00]
|
| [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.01]
|
| [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition\6.03]
|
| What I want to do, is see if the last key exists in a user's registry.
Note
| that each of the last 3 keys are sub keys and none of then have default
| values or value names below them.
|
| Here is a fragment of the code...
|
|
| var hasInstalledDevPartner = false;
| try
| {
|  var DevPartnerKey = "HKLM\\SOFTWARE\\NuMega\\BoundsChecker Visual C++
| Edition\\6.03\\";
|  var devPartnerVersion = WSHShell.RegRead(DevPartnerKey);
|
|   hasInstalledDevPartner = true;
| }
| catch (e)
| {
|  // Unable to read registry key
|  file://WScript.Echo("Problem: NuMega DevPartner 6.03 is not installed.
Error: " +
| e);
| }
|
| It seems like catching the error doesn't work for sub keys that are
| empty. I've tried both with and without the trailing backslash on the
| registry key.
|
| Any ideas? I'd rather not have to distribute a DLL and have everyone
| install the DLL and then run the script (heck, I'd might as well write
| a C++ or Java app, if I have to go that far... :^)
|
|
| PCM
|
| --------------------+------------------------+-------------------------
| Paul Michali        | PHONE/FAX              | PAGER
|                     |                        |
| Enhanced Services   | (800)-537-8662 x5-3200 | (800)-365-4578 (voice)
| Migration Bus. Unit | (603)-665-3200 (direct)| (888)-358-5637 (numeric)
|                     |                        |
| Cisco Systems, Inc. | EMAIL                  | EMAIL BASED PAGING
| 25 Sundial Ave.     |                        |

| --------------------+------------------------+-------------------------
|
|



Mon, 03 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
This seems to work for me...

************** Code snippet ***************
    On Error Resume Next

    Err.Clear
    PwdFlag = WSHShell.RegRead("HKLM\SomeKey")

    If (Err.Number = -2147024894) OR (PwdFlag(0) <> 1) Then
        Do Something
    End If
********************************************

Is there something not so cool about checking for this error number?

John Alderson
Systems Analyst
Goodwin, Procter & Hoar LLP



Tue, 04 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
Nothing except the fact that a missing key and one that exists but it's default
value isn't set gives the same error.  Some keys have no value, it's just the
existence on the key that's of significance.

--
Michael Harris


| This seems to work for me...
|
| ************** Code snippet ***************
|     On Error Resume Next
|
|     Err.Clear
|     PwdFlag = WSHShell.RegRead("HKLM\SomeKey")
|
|     If (Err.Number = -2147024894) OR (PwdFlag(0) <> 1) Then
|         Do Something
|     End If
| ********************************************
|
| Is there something not so cool about checking for this error number?
|
| John Alderson
| Systems Analyst
| Goodwin, Procter & Hoar LLP

|
|
|



Tue, 04 Dec 2001 03:00:00 GMT  
 How to determine if a Registry key exists?
Actually, this workaround doesn't work...

Writing a named value to a non-existent key with the Shell.RegWrite method
will simply create the missing key for you...

--
Michael Harris


| Someone (Jeff Mastry, I believe) posted a slick workaround that worked
| something like this...
|
| Try to write a dummy named value to the key (with error trapping enabled),
| using an arbitrary value name that you _know_ can't possibly exist (like
| MyDogsNameIs = "Fido").
|
| If the RegWrite of the dummy named value fails, then the parent key
doesn't
| exist.
|
| If it succeeds, it exists, so delete the dummy named value.
|
| --
| Michael Harris
|
|



| |
| | >
| | > you can use the On Error Resume Next construction to test a key's
| | > existence in VBscript.
| |
| | ...
| |
| | > In JScript 5.0 you can
| | > use the similar Try Catch technique to do the same.
| |
| | In my JScript code, I did a try..catch block, but I was seeing it
entering
| | the catch block for a key that does exist!  Here's the actual keys I'm
| | trying to access (which you can apply using regedit).
| |
| | REGEDIT4
| |
| | [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++ Edition]
| |
| | [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++
Edition\6.00]
| |
| | [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++
Edition\6.01]
| |
| | [HKEY_LOCAL_MACHINE\SOFTWARE\NuMega\BoundsChecker Visual C++
Edition\6.03]
| |
| | What I want to do, is see if the last key exists in a user's registry.
| Note
| | that each of the last 3 keys are sub keys and none of then have default
| | values or value names below them.
| |
| | Here is a fragment of the code...
| |
| |
| | var hasInstalledDevPartner = false;
| | try
| | {
| |  var DevPartnerKey = "HKLM\\SOFTWARE\\NuMega\\BoundsChecker Visual C++
| | Edition\\6.03\\";
| |  var devPartnerVersion = WSHShell.RegRead(DevPartnerKey);
| |
| |   hasInstalledDevPartner = true;
| | }
| | catch (e)
| | {
| |  // Unable to read registry key
| |  file://WScript.Echo("Problem: NuMega DevPartner 6.03 is not installed.
| Error: " +
| | e);
| | }
| |
| | It seems like catching the error doesn't work for sub keys that are
| | empty. I've tried both with and without the trailing backslash on the
| | registry key.
| |
| | Any ideas? I'd rather not have to distribute a DLL and have everyone
| | install the DLL and then run the script (heck, I'd might as well write
| | a C++ or Java app, if I have to go that far... :^)
| |
| |
| | PCM
| |
| | --------------------+------------------------+-------------------------
| | Paul Michali        | PHONE/FAX              | PAGER
| |                     |                        |
| | Enhanced Services   | (800)-537-8662 x5-3200 | (800)-365-4578 (voice)
| | Migration Bus. Unit | (603)-665-3200 (direct)| (888)-358-5637 (numeric)
| |                     |                        |
| | Cisco Systems, Inc. | EMAIL                  | EMAIL BASED PAGING
| | 25 Sundial Ave.     |                        |

| | --------------------+------------------------+-------------------------
| |
| |
|
|



Fri, 07 Dec 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. help please: example of seeing of a registry key exists

2. Detecing if a registry key exists

3. Check if registry key exists

4. help please: example of seeing of a registry key exists

5. Doe a registry key exist?

6. Registry key exists?

7. check if a certain registry key exists or not

8. Check if registry key exists

9. Does a key exist in registry

10. please Query the registry key existing?

11. find the specify Root key and Sub key from the registry

12. Deleting Registry key and sub-keys?

 

 
Powered by phpBB® Forum Software