Discussion:
newbie: errorhandling on wshshell.regread
(too old to reply)
Tim Moor
2005-11-28 21:16:25 UTC
Permalink
dear vbs gurus
the following code reports an error -> invalid root in registrykey, if the
registry key is not existent. why does my error handling not return ->
Function False instead of the error box displayed. thanx alot
tim


snip.........................

If CheckRegKey(strMapNameKey)= True then
MsgBox " Function True "
Else
MsgBox " Function False "
End If

Function CheckRegKey(RegStr)
On Error Resume Next
WshShell.RegRead RegStr
If Err Then
CheckRegKey = False
Else
CheckRegKey = True
End If
On Error Goto 0
End Function
Steven Burn
2005-11-28 22:06:02 UTC
Permalink
Try this....

Option Explicit
Dim strMapNameKey, lErrCode, sErrDesc
strMapNameKey = "HKCU\Software\"
If CheckRegKey(strMapNameKey)= True then
WScript.Echo "Function True "
Else
WScript.Echo "Function False " & vbcrlf & vbcrlf & "Err: " & lErrCode &
vbcrlf & "Desc: " & sErrDesc
End If

Function CheckRegKey(RegStr)
Dim wshShell, x
Set wshShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
x = wshShell.RegRead(RegStr)
If Err <> 0 Then
lErrCode = Err.Number: sErrDesc = Err.Description
CheckRegKey = False
Else
CheckRegKey = True
End If
Set wshShell = Nothing
End Function

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
Post by Tim Moor
dear vbs gurus
the following code reports an error -> invalid root in registrykey, if the
registry key is not existent. why does my error handling not return ->
Function False instead of the error box displayed. thanx alot
tim
snip.........................
If CheckRegKey(strMapNameKey)= True then
MsgBox " Function True "
Else
MsgBox " Function False "
End If
Function CheckRegKey(RegStr)
On Error Resume Next
WshShell.RegRead RegStr
If Err Then
CheckRegKey = False
Else
CheckRegKey = True
End If
On Error Goto 0
End Function
Loading...