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:
Can someone help me get the rest of this?
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)
Please log in to answer
Posted by:
itolutions
13 years ago
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
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
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.
so that the conversation will remain readable.