How can i find out if the RegRead operation was successful?
Printable View
How can i find out if the RegRead operation was successful?
whats this message is related to
wscripting technology?
Then: if you read something different by default values of type of key_value
you're reading, you read something.
RegRead will create an automation error, so you can use ON ERROR to determine if is was successfull or not in reading, say for example:
JeffBCode:Option Explicit
Private Sub Command1_Click()
On Error GoTo ErrReadingRegistry
Dim objShell As New WshShell
Dim strReturn As String
'This works "Systemtray"
strReturn = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray")
MsgBox strReturn
'This doesnt "Systemtray OOOPPPSS" and return an error
strReturn = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray OOOPPPSS")
MsgBox strReturn
Exit Sub
ErrReadingRegistry:
MsgBox "Error # " & Err.Number & vbCrLf & _
"Description: " & Err.Description
End Sub
Hallo Savitar,
here another way to do it
Code:
'==========================================================
' Name: ERROR_SUCCESS
' Purpose: All the access bits, not including MAXIMUM_ALLOWED,
' are granted and the GrantedAccessMask member is not zero.
' Remarks:
'==========================================================
Public Const ERROR_SUCCESS = 0&
'==========================================================
' Name: ERROR_CODE
' Purpose: Error code
' Remarks:
'==========================================================
Public Const ERROR_CODE = -1&
'==========================================================
' Name: fWSHGetRegKey
' Input:
' ByRef STRNAME As String
' ByRef vValue As Variant
' Output: Long
' Purpose: Returns the value of a key or value-name from the registry
' for the following value type REG_SZ, REG_DWORD, REG_BINARY,
' REG_EXPAND_SZ, REG_MULTI_SZ
' Remarks:
'==========================================================
Public Function fWSHGetRegKey(STRNAME As String, vValue As Variant) As Long
vValue = objWSH.RegRead(STRNAME)
If Err.Number <> ERROR_SUCCESS Then
fWSHGetRegKey = ERROR_CODE
End If
End Function
private myCallsub()
dim vValue as Variant
dim LngRetValue as long
dim strKey as String
strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Systemtray"
LngRetValue = fWSHGetRegKey(strKey ,vValue )
if LngRetValue = ERROR_SUCCESS then
'You can use here the readed value saved on vValue as you want.
end if
end sub