I need to read from a specific registry key and if it does NOT exist, display an error message, but if it DOES, then display some text and then what the key says.

This is what I have:

function readFromRegistry (strRegistryKey)
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
if err.number <> 0 then
readFromRegistry= strDefault
end if
set WSHShell = nothing
end function

str = readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\VDG\Agent Version")
wscript.echo "Digital Guardian Version: " & str

Can someone help me get the rest of this?
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.



Function ReadValue(valuePath, outValue)
On Error Resume Next
ReadValue = false
outValue = oShell.RegRead(valuePath)
If Err.Number=0 Then
ReadValue = True
End If
On Error Goto 0
End Function

example of using:

Dim strVariable
If Not ReadValue("HKLM\Software\MyApp\MyValue",strVariable) Then
MsgBox "Can't read ...."
MsgBox "My value is " & strVariable
End if

Answered 07/29/2011 by: itolutions
Orange Senior Belt

Please log in to comment
Ok great! Thank you for that. On a second note, I need to read more than just the 1 registry key and output to the screen. I have it working, but on one of the keys there could be different values that indicate different versions. Is there a way to set it so that if the registry key value = a, it will output "Version A", and b, c, etc...

I tried setting up an if then statement but it failed. I am still reasearching this and trying to get it right
Answered 07/29/2011 by: kool_zero
Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity