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

Registry : Read method

0 views
Skip to first unread message

Luigi Bennardi

unread,
Jun 20, 2000, 3:00:00 AM6/20/00
to
Hi,

I have some troubles with my code (see bellow). I would like to check if
this Key exists or not. In the docmentation I have followed (I think) the
procedure but for no reason it dosen't work?.
Thanks

Luigi

My code :

Dim varrecup

Set WshShell = WScript.CreateObject("WScript.Shell")
varrecup=WshShell.RegRead("HKLM\SOFTWARE\Object Design
Inc.\ObjectStore\5.1\")

Michael Harris

unread,
Jun 20, 2000, 3:00:00 AM6/20/00
to
You have to enable error handling with "On Error Resume Next" and check for an error. You can't
distinguish a (a) "key not found" from a (b) "key has no default value" based solely on the
err.number, both raise error 0x80070002.

You have to examine the err.description (a somewhat ugly solution):

In case (a) the description is:
Invalid root in registry key "HKEY_CURRENT_USER\Software\BlahBlah\".

In case (b) it's:
Unable to open registry key "HKEY_CURRENT_USER\Software\" for reading.

So use somthing like this after the RegRead:

If err then
if left(err.description,7) = "Invalid" then
'not found...
elseif left(err.description,6) = "Unable" then
'no default value set, but key exists...
else
'unexpected error
end if
end if

--
Michael Harris
MVP Scripting


"Luigi Bennardi" <lui...@ctech.ca> wrote in message news:O1boUus2$GA.271@cppssbbsa04...

Luigi Bennardi

unread,
Jun 20, 2000, 3:00:00 AM6/20/00
to
Thanks Michael for your answer.

For my understanding :

Case 1 : If I have a key with no defined value.... I will get an error
message "Unable to open ..."
Case 2 : If I have a key with a value (1,REG_DWORD)... I will get my value
... not the name of my KEY. So my question is can we get key name trough
vbs
Case 3: If I have a bad root...... I will get an error message "Invalid root

PS : sorry for my bad English.

Luigi
"Luigi Bennardi" <lui...@ctech.ca> wrote in message news:...

Michael Harris

unread,
Jun 20, 2000, 3:00:00 AM6/20/00
to
Case 1 : If I have a key with no defined value.... I will get an error
message "Unable to open ..."

===> correct...

Case 2 : If I have a key with a value (1,REG_DWORD)... I will get my value
... not the name of my KEY.

===> correct

So my question is can we get key name trough
vbs

===> you need the key name to do the RegRead to start with. If you mean discovering the names of
subkeys or named values, RegRead doesn't support it.

Case 3: If I have a bad root...... I will get an error message "Invalid root

===> correct

0 new messages