Hello,
i'am trying to read the value IconUnderline which exist on that path
i never worked beforewith REG_NONECode:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\IconUnderline
Thanks :)
Printable View
Hello,
i'am trying to read the value IconUnderline which exist on that path
i never worked beforewith REG_NONECode:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\IconUnderline
Thanks :)
check the key, shows with the type he says
from http://connect.microsoft.com/VisualS...edbackID=97603Quote:
Thank you for reporting this issue with the RegistryKey.GetValue method.
Unfortunately GetValue does not support reading values of type REG_NONE or REG_LINK at this time. We will consider adding this support for version 3 of the .NET Framework.
Thanks,
Josh Free
A REG_NONE is merely a string represented in hex. Read it just as you would a REG_SZ string without a null terminating character. You need to use the registry APIs to do this, as it is not supported by WSH or WMI.
In NET, you read it into a byte array (with GetValue) then optionally use BitConverter to convert it to a string.
can you some help with a sample
basic code reading registry dont work with the case REG_NONE
it show blank only
Thanks
Post the code that you have already and we can go through it to show you where you need to make changes.
Hi i use this code for reading but show blank
Code:Private Function Registry_Read(Key_Path, Key_Name) As Variant
On Error Resume Next
Dim Registry As Object
Set Registry = CreateObject("WScript.Shell")
Registry_Read = Registry.RegRead(Key_Path & Key_Name)
End Function
Private Sub Form_Load()
MsgBox Registry_Read("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\", "IconUnderline")
End Sub
Use this instead. A REG_NONE can contain anything, so the data type you specify for lpData in RegQueryValueEx determines the outcome. In this case IconUnderline appears to be a number. The following example can provide either a hex string or a number.
vb Code:
'Form level code. Option Explicit Private Sub Form_Load() Const HKEY_LOCAL_MACHINE = &H80000002 Const SUBKEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" Const VALUE_NAME = "IconUnderline" MsgBox RegReadNoneString(HKEY_LOCAL_MACHINE, SUBKEY, VALUE_NAME) End Sub
vb Code:
'Module level code. Option Explicit Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _ (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _ ByVal samDesired As Long, ByRef phkResult As Long) As Long Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _ (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _ ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long) As Long Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long Public Const REG_OPTION_RESERVED = 0& Public Const KEY_QUERY_VALUE = &H1 Public Const ERROR_SUCCESS = 0& Public Const ERROR_MORE_DATA = 234 Public Const REG_NONE = 0 Public Function RegReadNoneString(lngHKey As Long, strSubKey As String, strValueName As String) As String Dim lngErrVal As Long Dim lngKeyHandle As Long Dim lngDataType As Long Dim lngDataSize As Long Dim intIndex As Integer Dim bytRetVal() As Byte Dim strRetVal As String Dim lngRetVal As Long 'Open the new key. lngErrVal = RegOpenKeyEx(lngHKey, strSubKey, REG_OPTION_RESERVED, KEY_QUERY_VALUE, lngKeyHandle) If lngErrVal = ERROR_SUCCESS Then 'Get the key`s data length. It should return ERROR_MORE_DATA. lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, lngDataType, 0&, lngDataSize) 'Size the data array. ReDim bytRetVal(lngDataSize) If lngErrVal = ERROR_MORE_DATA Then 'Test for REG_NONE. If lngDataType = REG_NONE Then 'Get the current value. lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize) End If ''//////////////////////////////////////////////// ''Format the data into a binary string. For intIndex = 0 To lngDataSize - 1 strRetVal = strRetVal & Right("00" & bytRetVal(intIndex), 2) & " " Next strRetVal = Left$(strRetVal, Len(strRetVal) - 1) RegReadNoneString = strRetVal ''//////////////////////////////////////////////// ''Alternative for a LONG. ' lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, lngRetVal, lngDataSize) ' RegReadNoneString = CStr(lngRetVal) ''//////////////////////////////////////////////// End If End If 'Close any key opened with RegOpenKeyEx. Call RegCloseKey(lngKeyHandle) End Function
Hi schoolbusdriver ,
Thanks for your sample but seem that dont work with other
i tested with IconUnderline is fine it return the true value
but when i tested with others it show wrong value
how can that happen ?
here you how it look like
http://i32.tinypic.com/10gzhav.jpg
Thanks
Unlike other data types, the data in a REG_NONE is undefined, so it is up to YOU :) to interpret the data. The "wrong" data you're showing is actually the decimal value of the hex data....
As it is 5 bytes long it is probably a string - the last "00" being a null, so instead of using
orCode:lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize)
tryCode:lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, lngRetVal, lngDataSize)
Bear in mind that the data may also be mix of data types that are supposed to be put into a UDT - so unless you know the structure of the UDT it may not be decipherable.Code:lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, strRetVal, lngDataSize)
If it's not a value that you have written, count the bytes.......
Hi ,
When you added it crash application
unless there is a way of this crash to be fixed i will use the byteCode:lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, strRetVal, lngDataSize)
and convert it from Dec2Hex even sometimes it got more than 5 byte..Code:lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize)
do you have any tips or good idea schoolbusdriver ?
Thanks
My bad, it should have been "ByVal strRetVal" i.e.
vb Code:
Public Function RegReadNoneString(lngHKey As Long, strSubKey As String, strValueName As String) As String Dim lngErrVal As Long Dim lngKeyHandle As Long Dim lngDataType As Long Dim lngDataSize As Long Dim strRetVal As String 'Open the new key. lngErrVal = RegOpenKeyEx(lngHKey, strSubKey, REG_OPTION_RESERVED, KEY_QUERY_VALUE, lngKeyHandle) If lngErrVal = ERROR_SUCCESS Then 'Get the key`s data length. It should return ERROR_MORE_DATA. lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, lngDataType, 0&, lngDataSize) If lngErrVal = ERROR_MORE_DATA Then 'Test for REG_NONE. If lngDataType = REG_NONE Then 'Size the string. strRetVal = Space$(lngDataSize) 'Get the current value. lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, ByVal strRetVal, lngDataSize) RegReadNoneString = strRetVal End If End If End If 'Close any key opened with RegOpenKeyEx. Call RegCloseKey(lngKeyHandle) End Function
How you convert it depends on what you want to display.
If you are confident handling the registry you could try the following.
Create a plain text file containing:
Rename it to "test.reg" and double click on it and merge it with the registry. This will put the binary data you mentioned into the same subkey that contains "IconUnderline".Code:Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer]
"Test"=hex(0):3e,3d,3c,3a,00
Use the code in this post to read the value "Test". The message box will display the ascii string:- >=<:
Don't forget to delete it when you've done.
With a REG_NONE it's a case of "what do you want to do". Because it's undefined you could, for example, use it to store an encrypted gif of a password :)
Any other tips will cost you lots of hard cash :lol:
Hi,
your last update didnt work show blank
so i think i will stay on Dec2hex way work for now
i really appreciate your help schoolbusdriver
cheerz & Thanks ;)