/build/static/layout/Breadcrumb_cap_w.png

VB Script to read registry key and display it or display error

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
else
readFromRegistry=value
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

Answers (2)

Posted by: itolutions 13 years ago
Purple Belt
0

Function ReadValue(valuePath, outValue)
On Error Resume Next
Err.Clear
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 ...."
Else
MsgBox "My value is " & strVariable
End if

Posted by: kool_zero 13 years ago
Yellow Belt
0
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ