Newsgroup: it.comp.lang.visual-basic
Titolo: Visualizzare valori Binari del registry ???

Salve a tutti,
con il seguente listato riesco a visualizzare valori del registry di tipo
string senza nessun problema ma sa il valore della chiave che voglio
visualizzare è di tipo binario in output ottengo una stinga vuota (senza
nessun valore).
La mia domanda è : Come posso ottenere dal registry il valore di una chiave
se essa è di tipo binary ??????
Private Sub LeggiValore_Click()
Dim Oggetto As New RegClass
Dim Chiave As String, Nome As String
Chiave = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Nome = "SystemTray"
MsgBox Oggetto.ResultString
End Sub
P.S. in questo esempio ho utilizzato le API di Windows ........ma non sono
vincolato al loro utilizzo ... se conoscete un altro sistema per
visualizzare correttamente chiavi di tipo binario sarei felice di ricevere
un vostro aiuto.
Grazie

 nessun valore).
Sono un po' di fretta, e le routines che ti passo sarebbero da adattare
al tuo caso...
In particolare: cosě come sono servono a simulare GetSetting e
SaveSetting di VB.
Prova a estrarre solo il codice che ti serve, e se hai problemi fammi
sapere.
Ciao
Flavio Ronco
----
P.S. Ci sono solo le dichiarazioni strettamente necessarie.
---------------------------------
Option Explicit
' API Win32 (Registry Management) 
---------------------------------------------------------
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const SKEY_VB_SETTINGS = "Software\VB and VBA Program Settings"
Public Const HKEY_VB_ROOT = HKEY_CURRENT_USER
Public Const REG_BINARY = 3
Public Const REG_SZ = 1
Public Const ERROR_NO_MORE_ITEMS = 259&
Public Const ERROR_SUCCESS = 0&
Public Const SYNCHRONIZE = &H100000
'Reg Key Security Options...
Public Const KEY_NOTIFY = &H10
Public Const READ_CONTROL = &H20000
Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_EVENT = &H1
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_WRITE = KEY_SET_VALUE + KEY_CREATE_SUB_KEY +
READ_CONTROL
Public Const KEY_EXECUTE = KEY_READ
Public Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE _
                            + KEY_CREATE_SUB_KEY +
KEY_ENUMERATE_SUB_KEYS _
                            + KEY_NOTIFY + KEY_CREATE_LINK +
READ_CONTROL
Public Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Boolean
End Type
'Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias
"RegCreateKeyExA" _
                                (ByVal hKey As Long, ByVal lpSubKey As
String, _
                                 ByVal Reserved As Long, ByVal lpClass
As String, _
                                 ByVal dwOptions As Long, ByVal
samDesired As Long, _
                                  lpSecurityAttributes As
SECURITY_ATTRIBUTES, _
                                 phkResult As Long, lpdwDisposition As
Long) As Long
Private Declare Function RegCreateKeyEx2 Lib "advapi32.dll" Alias
"RegCreateKeyExA" _
                                (ByVal hKey As Long, ByVal lpSubKey As
String, _
                                 ByVal Reserved As Long, ByVal lpClass
As String, _
                                 ByVal dwOptions As Long, ByVal
samDesired As Long, _
                                  ByVal lpSecurityAttributes As Long, _
                                 phkResult As Long, lpdwDisposition As
Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
Reserved As Long, ByVal dwType As Long, lpData As String, ByVal cbData
As Long) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias
"RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal
lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType
As Long, lpData As Byte, lpcbData As Long) As Long
Public Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As Long, lpcbData 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, lpType As Long, ByVal szData As String,
lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As
Long) As Long
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, phkResult As Long) As Long
----------------------------------------
'Preleva una STRINGA da una chiave binaria salvata con BinSaveSetting
Public Function BinGetSetting(ByVal AppName As String, ByVal Section As
String, ByVal Key As String, Optional Default As String = "") As String
    Dim lResult As Long
    Dim hKeyHandle As Long
    Dim sSubKey As String
    Dim sValue As String
    Dim lSize As Long
    Dim lType As Long
 
    sSubKey = SKEY_VB_SETTINGS & "\" & AppName & "\" & Section
    lResult = RegOpenKeyEx(HKEY_VB_ROOT, sSubKey, 0, KEY_ALL_ACCESS,
hKeyHandle)
 
    If lResult Then '(error)
        BinGetSetting = Default
    Else
        lResult = RegQueryValueExNULL(hKeyHandle, Key, 0&, lType, 0&,
lSize)
        If lResult Then '(error)
            BinGetSetting = Default
        Else
            sValue = String(lSize, " ")
            lResult = RegQueryValueEx(hKeyHandle, Key, 0, lType, sValue,
lSize)
            BinGetSetting = Left$(sValue, lSize - 1)
        End If
    End If
 
    If hKeyHandle Then Call RegCloseKey(hKeyHandle)
 
End Function
'Salva una STRINGA come valore binario.
'Nel registry risulta una serie di bytes che rappresentano
'la versione ANSI della stringa, Null terminated (l'ultimo Byte č zero)
'Se la stringa contiene caratteri null all'interno viene salvata
correttamente
Public Sub BinSaveSetting(ByVal AppName As String, ByVal Section As
String, ByVal Key As String, ByVal Setting As String)
    Dim lResult As Long
    Dim hKeyHandle As Long
    Dim sSubKey As String
    Dim sValue As String
    Dim lSize As Long
    Dim r As Long
 
    sSubKey = SKEY_VB_SETTINGS & "\" & AppName & "\" & Section
    sValue = CStr(Setting)
 
    lResult = RegCreateKeyEx2(HKEY_VB_ROOT, sSubKey, 0&, vbNullString,
0&, KEY_ALL_ACCESS, 0&, hKeyHandle, r)
 
    If lResult = 0 Then
        lSize = Len(Setting) + 1
        lResult = RegSetValueEx(hKeyHandle, Key, 0&, REG_BINARY, ByVal
sValue, lSize)
    End If
 
    If hKeyHandle Then RegCloseKey (hKeyHandle)
 
End Sub
-- 
f.ronco@*NonMiServeNiente*
flashnet.it
http://www.metabrains.com
  [Under Construction]
-------------------------------------------------------------
"Che pubblico in gamba! Se ci dite dove lavorate,
domani mattina se abbiamo tempo vi veniamo a vedere"
[Paolo Rossi]