Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invalid root in registry key

4,080 views
Skip to first unread message

yawnmoth

unread,
Feb 14, 2008, 9:52:26 PM2/14/08
to
Whenever I try to run the following, I get an error I don't quite
understand:

Dim WshShell, value
Set WshShell = WScript.CreateObject("WScript.Shell")

value = WshShell.RegRead("HKEY_CLASSES_ROOT\Software\SoundRec
\FriendlyTypeName")
WScript.Echo value

Here's the error:

Script: C:\test\test.vbs
Line: 4
Char: 1
Error: Invalid root in registry key "HKEY_CLASSES_ROOT\Software
\SoundRec\FriendlyTypeName".
Code: 80070002
Source: WshShell.RegRead

Any ideas?

mayayana

unread,
Feb 14, 2008, 11:11:36 PM2/14/08
to

The error means the key or value does not exist.
It's actually a handy way to test for an existing
key or value. (This function assumes WScript.Shell
has been created as SH):

Function Exists(RegPath)
Dim r
On Error Resume Next
Err.clear
r = SH.RegRead(RegPath)
If hex(Err.number) = "80070002" Then
Exists = False
Else
Exists = True
End If
End Function

Also, you don't have to use the long key name.
HKCR will also work.

Paul Randall

unread,
Feb 15, 2008, 12:55:05 AM2/15/08
to
Is the "Err.clear" statement really necessary?
The scripting help files says:
The Err object's properties are reset to zero or zero-length strings
("") after an On Error Resume Next statement. The Clear method can be
used to explicitly reset Err.

-Paul Randall

"mayayana" <mayaXX...@mindXXspring.com> wrote in message
news:uALawj4b...@TK2MSFTNGP04.phx.gbl...

mayayana

unread,
Feb 15, 2008, 8:59:20 AM2/15/08
to
> Is the "Err.clear" statement really necessary?
> The scripting help files says:
> The Err object's properties are reset to zero or zero-length strings
> ("") after an On Error Resume Next statement. The Clear method can be
> used to explicitly reset Err.
>
Yes, I've read that. I don't really have a good
reason to do it the way I do, other than that I
like to be explicit in cases where I'm going to actually
check the error number. And I find it counter-intuitive
and confusing to connect the error action with the
error value.

0 new messages