How To Get Value From Registry Entry
Given the following Registry Info how do I extract the value from a SubItem?
HKEY_LOCAL_MACHINE\SOFTWARE\RealNetworks\RealPlayer\version
By looking into the registry the value of version is 6.0.14.806. How do I code to get that value into a variable?
Re: How To Get Value From Registry Entry
how you want to do?
apis or scripting
edit, here is a very simple script example
Code:
Dim wsh, str
on error resume next
Set wsh = CreateObject("WScript.Shell")
str = wsh.RegRead("HKCR\.pid\") ' change to suit your key
'msgbox err.number
' if err.number = "-2147024894" then str = "filetype not registered"
msgbox str
1 Attachment(s)
Re: How To Get Value From Registry Entry
Heres a module I made just for reading HKEY_LOCAL_MACHINE sinces thats pretty much all I ever need anyway.
Debug.Print sdaGetRegEntry("SOFTWARE\RealNetworks\RealPlayer\", "version")
Re: How To Get Value From Registry Entry
Quote:
Originally Posted by westconn1
how you want to do?
apis or scripting
edit, here is a very simple script example
Code:
Dim wsh, str
on error resume next
Set wsh = CreateObject("WScript.Shell")
str = wsh.RegRead("HKCR\.pid\") ' change to suit your key
'msgbox err.number
' if err.number = "-2147024894" then str = "filetype not registered"
msgbox str
Nope, returns an empty value. I did subsitute with my key like this
str = wsh.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RealNetworks\RealPlayer\version")
and also like this:
str = wsh.RegRead("HKLM\SOFTWARE\RealNetworks\RealPlayer\version")
Re: How To Get Value From Registry Entry
You'll may have to explicitly declare the variable types if you're doing it in VB6 rather than a vbs script. i.e.
vb Code:
Private Sub Form_Load()
Dim WshShell As Object
Dim strValue As String
Set WshShell = CreateObject("Wscript.Shell")
MsgBox WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RealNetworks\RealPlayer\version")
End Sub
Re: How To Get Value From Registry Entry
i tested code in vb6, did not return for that key as i don't have, but worked ok for others
try a \ at the end of the string if it is a default value rather than a named value
"HKLM\SOFTWARE\RealNetworks\RealPlayer\version\"
Re: How To Get Value From Registry Entry
Below works
Code:
Dim WshShell As Object
Dim strValue As String
Set WshShell = CreateObject("Wscript.Shell")
strValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RealNetworks\RealPlayer\version")
Below also works
Code:
Dim VersionNumber As String
VersionNumber = sdaGetRegEntry("SOFTWARE\RealNetworks\RealPlayer", "version")
Now here is where neither one works and I don't understand why.
On this one I get a Type Mismatch
Code:
Dim WshShell As Object
Dim strValue As String
Set WshShell = CreateObject("Wscript.Shell")
strValue = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Bags\1\Desktop\ItemPos1024x768(1)")
And on this one.....
Please note that in the function sdaGetRegEntry
I changed this:
If Not ERROR_SUCCESS = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKeys, 0&, KEY_READ, lngHandle) Then Exit Function
to this:
If Not ERROR_SUCCESS = RegOpenKeyEx(HKEY_CURRENT_USER, strSubKeys, 0&, KEY_READ, lngHandle) Then Exit Function
....and it just returns a null value.
Code:
Dim Positions As String
Positions = sdaGetRegEntry("Software\Microsoft\Windows\Shell\Bags\1\Desktop", "ItemPos1024x768(1)")
Re: How To Get Value From Registry Entry
Quote:
Dim WshShell As Object
Dim strValue() As Variant
Set WshShell = CreateObject("Wscript.Shell")
strValue = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Bags\1\Desktop\ItemPos1024x768( 1)")
this works for me, but only as a variant OR variant array
returns an array of
0 to 3423 on my computer
it maybe that it should return a TYPE of some sort
Re: How To Get Value From Registry Entry
Windows Scripting Host can't be used to retrieve strings from REG_BINARY entries, only numbers. It can't cope with UDTs either - there's a limit to the size of the returned array that it can handle.
EDIT: I had put some API code in here that would put REG_BINARY data in a UDT, but looking at the registry entry again, I've realised it contains an arry of UDTs. You'll first need to deduce the structure of the data the ValueName contains. Right-click in regedit and pick "Modify binary data" to copy/paste...