se ho ben capito questo codice dovrebbe fare il caso tuo
UTILIZZO
'************************************************* **********
'-----------------------------
'cosi per creare la chiave:
'-----------------------------
nome_stringa$ = "Nome di Esempio"
valore$ = "qualsiasi cosa"
PutRegString HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run ", nome_stringa$, valore$
'nome_stringa$, è il Nome stringa all'interno della chiave Run
'valore$, è il valore associato a nome_stringa$
'-----------------------------
'cosi per leggere la chiave:
'-----------------------------
nome_stringa$ = "Nome di Esempio"
valore$ = GetRegString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run ", nome_stringa$, "")
'valore$ contiene "qualsiasi cosa"
'************************************************* **********
'INSERE IN UN MODULO
'************************************************* **********
Private Const REG_SZ = 1
Private Const ERROR_SUCCESS = 0&
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private 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 Any, ByVal cbData As Long) As Long
'registro
Enum regOptions
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_CURRENT_CONFIG = &H80000005 '*
HKEY_DYN_DATA = &H80000006 '*
HKEY_PERFORMANCE_DATA = &H80000004 '*
End Enum
'scrittura, eliminazione nel registro di configurazione
Sub PutRegString(hKey As regOptions, strPath As String, strValue As String, strData As String)
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData))
If lRegResult <> ERROR_SUCCESS Then
MsgBox "Scrittura nel registro fallita", vbCritical
End If
lRegResult = RegCloseKey(hCurKey)
End Sub
'lettura dal registro di configurazione
Public Function GetRegString(hKey As regOptions, strPath As String, strValue As String, Optional Default As String) As String
Dim hCurKey As Long
Dim lValueType As Long
Dim strBuffer As String
Dim lDataBufferSize As Long
Dim intZeroPos As Integer
Dim lRegResult As Long
' Setup valore default
If Not IsEmpty(Default) Then
GetRegString = Default
Else
GetRegString = ""
End If
' Apre la key e legge la lunghezza della stringa
lRegResult = RegOpenKey(hKey, strPath, hCurKey)
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, ByVal 0&, lDataBufferSize)
If lRegResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
' inizializza il buffer della stringa e la sostituisce
strBuffer = String(lDataBufferSize, " ")
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, ByVal strBuffer, lDataBufferSize)
' formato stringa
intZeroPos = InStr(strBuffer, Chr$(0))
If intZeroPos > 0 Then
GetRegString = Left$(strBuffer, intZeroPos - 1)
Else
GetRegString = strBuffer
End If
End If
Else
' ci sono probblemi....
End If
lRegResult = RegCloseKey(hCurKey)
End Function
'************************************************* **********
Ciao![]()


Rispondi quotando