¿Cómo puedo leer el valor de una clave del registro de windows con visual basic 6?. He mirado por ahí y he visto algo relacionado con las API, pero no llego a entenderlo. ¿Me podríais pasar algún ejemplillo?.
Respuesta de MANUEL LOPEZ ALVAREZ
1
1
MANUEL LOPEZ ALVAREZ, Grandes conocimientos en Informatica General, Programacion en...
Hace un par de día hice yo en modo usuario esa misma pregunta aun experto y me contexto lo siguiente: Aqui te envio el codigo para manejar el registro de windows. Create un modulo y copiate el codigo, despues desde tu programa llama a la funcion que deses ya sea modificar, borrar o añadir claves Salu2 (Te he comentado el codigo para que no te pierdas en todo caso para cualquier duda dame un toque) Option Explicit 'Contantes para crear claves Public Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Long End Type Public Const REG_SZ As Long = 1 Public Const REG_DWORD As Long = 4 'Constantes para la Raiz Public Const HKEY_CLASSES_ROOT = &H80000000 Public Const HKEY_CURRENT_USER = &H80000001 Public Const HKEY_LOCAL_MACHINE = &H80000002 Public Const HKEY_USERS = &H80000003 'Otras constantes Public Const KEY_ALL_ACCESS = &H3F Public Const REG_OPTION_NON_VOLATILE = 0 'Abrir una clave 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 'Cerrar una clave Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long 'Crear una clave Public 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 'Borrar una clave Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long 'Recuperar un valor, sea long o string Public 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 'Crea o modifica un valor string 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, ByVal lpData As Any, ByVal cbData As Long) As Long 'Crea o modifica un valor long Public Declare Function RegSetValueExL 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 'Borra un valor, sea long o string Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long 'Ajuste para eliminar una clave Public Sub EliminarClave(Raiz As Long, Clave As String) 'El valor de retorno de la función Dim Retorno As Long Retorno = RegDeleteKey(Raiz, Clave) End Sub 'Ajuste para eliminar un valor Public Sub EliminarValor(Raiz As Long, Clave As String, Valor As String) 'El valor de retorno de la función Dim Retorno As Long 'Manejador de la clave Dim Manejador As Long 'Abrimos la clave Retorno = RegOpenKeyEx(Raiz, Clave, 0, KEY_ALL_ACCESS, Manejador) 'Eliminamos el valor buscado Retorno = RegDeleteValue(Manejador, Valor) 'Cerramos la clave RegCloseKey (Manejador) End Sub 'Ajuste para recuperar una cadena Function GetDatoString(Raiz As Long, Clave As String, Valor As String) As String On Error Resume Next 'Manejador de la clave Dim Manejador As Long 'Longitud de la cadena Dim Longitud As Long 'Variable para colocar el dato Dim Dato As String 'El valor de retorno de la función Dim Retorno As Long 'Abrimos la clave Retorno = RegOpenKeyEx(Raiz, Clave, 0, KEY_ALL_ACCESS, Manejador) 'Longitud del dato Retorno = RegQuer