Borrar Clave desde Vb6

Iniciado por Rudy21, 3 Junio 2006, 03:13 AM

0 Miembros y 1 Visitante están viendo este tema.

Rudy21

pues eso...

Como borrar Clave del Registro desde Vb6

gracias


Gorky

Con la API de windows.

Esto en la declaracion:
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
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As LongPrivate Const HKEY_LOCAL_MACHINE = &H80000002


Esto en la funcion:
RegOpenKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentversion\run", h
RegDeleteKey h, "Key_a_borrar"
RegCloseKey h



Eso seria solo la version resumida y ya hecha.
Tambien hay un post donde se trata esto ampliamente. http://foro.elhacker.net/index.php/topic,13480.0.html

WarGhost

Aqui te dejo un modulo muy completo para manejar en registro con las API.

Option Explicit

Public Keys_Registro As String
Public READ_Valor_Key As String
Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
End Type
Global Const REG_SZ = 1
Global Const REG_BINARY = 3
Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_CONFIG = &H80000005
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_DYN_DATA = &H80000006
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_USERS = &H80000003
Global Const ERROR_SUCCESS = 0&
Global Const KEY_ENUMERATE_SUB_KEYS = &H8
Global Const KEY_QUERY_VALUE = &H1
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, 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, lpType As Long, lpData As Any, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
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 Any, ByVal cbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Dim Carpetas_Registro As String

Public Sub Reg_Crea_KeyConValor(hKey As Long, carpeta As String, Nombre_Key As String, contenido_key As String)
Dim res
RegOpenKey hKey, carpeta, res
RegSetValueEx res, Nombre_Key, 0, REG_SZ, ByVal contenido_key, Len(contenido_key)
RegCloseKey res
End Sub

Public Sub Reg_Borra_Key(hKey As Long, strPath As String, strValue As String)
Dim Ret
RegOpenKey hKey, strPath, Ret
RegDeleteValue Ret, strValue
RegCloseKey Ret
End Sub

Public Sub Reg_Abre_Carpeta(hKey As Long, nombre_folderkey As String)
Dim res
RegOpenKeyEx HKEY_CURRENT_USER, nombre_folderkey, 0, 0, res
End Sub
Public Sub Reg_Cierra_carpeta()
Dim res
RegCloseKey HKEY_CURRENT_USER
End Sub

Public Sub Reg_Lee_Keys(hKey As Long, ruta As String)

Dim valuename As String
    Dim valuelen As Long
    Dim datatype As Long
    Dim data(0 To 254) As Byte
    Dim datalen As Long
    Dim datastring As String

    Dim index As Long
    Dim c As Long
    Dim retval As Long
    READ_Valor_Key = ""
    retval = RegOpenKeyEx(hKey, ruta, 0, KEY_QUERY_VALUE, hKey)
    If retval <> 0 Then
       
        'End
    End If
   
    index = 0
    While retval = 0

        valuename = Space(255)
        valuelen = 255
        datalen = 255

        retval = RegEnumValue(hKey, index, valuename, valuelen, 0, datatype, data(0), datalen)
        If retval = 0 Then
            valuename = Left(valuename, valuelen)
           
            READ_Valor_Key = READ_Valor_Key & "Key: " & valuename & vbCrLf
            Select Case datatype
            Case REG_SZ
                datastring = Space(datalen - 1)
                CopyMemory ByVal datastring, data(0), datalen - 1
               
               
                READ_Valor_Key = READ_Valor_Key & "      Valor: " & datastring & vbCrLf
            Case REG_BINARY
                Dim ttStr As String
                ttStr = ""
               
                For c = 0 To datalen - 1
                    datastring = Hex(data(c))
                    If Len(datastring) < 2 Then datastring = _
                        String(2 - Len(datastring), "0") & datastring
                   
                    ttStr = ttStr & datastring & " "
                Next c
               
            READ_Valor_Key = READ_Valor_Key & "      Valor: " & ttStr & vbCrLf
            Case Else
               
            End Select
        End If
        index = index + 1
    Wend
    retval = RegCloseKey(hKey)
End Sub

Public Sub Reg_Lee_carpetas(hKey As Long, carpeta As String)
Dim keyname As String
Dim keylen As Long
Dim classname As String
Dim classlen As Long
Dim lastwrite As FILETIME
Carpetas_Registro = ""
Dim index As Long
Dim retval As Long
retval = RegOpenKeyEx(hKey, carpeta, 0, KEY_ENUMERATE_SUB_KEYS, hKey)
    If retval <> 0 Then
    End If
    index = 0
    While retval = 0
      keyname = Space(255): classname = Space(255)
      keylen = 255: classlen = 255
      retval = RegEnumKeyEx(hKey, index, keyname, keylen, ByVal 0, classname, classlen, lastwrite)
      If retval = 0 Then
        keyname = Left(keyname, keylen)
        classname = Left(classname, classlen)
        If carpeta = "" Then
            Carpetas_Registro = Carpetas_Registro & keyname & vbCrLf
        Else
            Carpetas_Registro = Carpetas_Registro & carpeta & "\" & keyname & vbCrLf
        End If
       End If
      index = index + 1
    Wend
    retval = RegCloseKey(hKey)
End Sub

Public Sub Reg_Leer_ValorKey(hKey As Long, Carpeta_Key As String, Nombre_Key As String)
Dim cadena As String
cadena = String(255, Chr(0))
Dim res As Long
RegOpenKey hKey, Carpeta_Key, res
RegQueryValueEx res, Nombre_Key, 0, REG_SZ, ByVal cadena, Len(cadena)


RegCloseKey res
End Sub

Public Sub Reg_Borra_Carpeta(hKey As String, del_carpeta As String)
RegDeleteKey hKey, del_carpeta
End Sub

Public Sub Reg_Crear_carpeta(hKey As Long, Crear_carpeta As String)
Dim res As Long
RegCreateKey hKey, Crear_carpeta, res

RegCloseKey res
End Sub

Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String)
    Dim lResult As Long
    Dim lValueType As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim intZeroPos As Integer
   
    lResult = RegQueryValueEx(hKey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lResult = ERROR_SUCCESS Then
        If lValueType = REG_SZ Then
            strBuf = String(lDataBufSize, " ")
            lResult = RegQueryValueEx(hKey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
            If lResult = ERROR_SUCCESS Then
                intZeroPos = InStr(strBuf, Chr$(0))
                If intZeroPos > 0 Then
                   RegQueryStringValue = Left$(strBuf, intZeroPos - 1)
                Else
                   RegQueryStringValue = strBuf
                End If
            End If
        End If
    End If
End Function


Public Function GetStringKey(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String) As String
    Dim keyhand&
    Dim datatype&
    Dim r
   
    r = RegOpenKey(hKey, strPath, keyhand&)
    GetStringKey = RegQueryStringValue(keyhand&, strValue)
    r = RegCloseKey(keyhand&)
End Function


Este codigo no es muy ,No se nisiquiera la fuente.

;D Salu2, WarGhost
¿Qué culpa tengo yo de tener la sangre roja y el corazón a la izquierda?

Rudy21

#3
Hola, Muchas Gracias ahora...

Gorky tu code me marka un eror aki:

Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As LongPrivate

Dice

User-dfined type not defined


y no c k hacer

WarGhost
gracias  ti tmb ahora pruebo tu modulo (el k postiaste k dijiste k no es tuyo xD jaja )

y Solo Para Aclarar Borre laClav del Registro de la Siguiente Manera:

Set borrar = CreateObject("WScript.Shell")
borrar.RegDelete ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CLAVEABORRAR")



gracias

y Salu2


Gorky

Tuve un error al hacer copy & paste. Te lo posteo de nuevo:

Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

WarGhost

Cita de: Rudy21 en  3 Junio 2006, 23:52 PM
y Solo Para Aclarar Borre laClav del Registro de la Siguiente Manera:

Set borrar = CreateObject("WScript.Shell")
borrar.RegDelete ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CLAVEABORRAR")


eso es vbs.

;D Salu2, WarGhost
¿Qué culpa tengo yo de tener la sangre roja y el corazón a la izquierda?

The Shredder

Cita de: WarGhost en  4 Junio 2006, 15:59 PM
Cita de: Rudy21 en  3 Junio 2006, 23:52 PM
y Solo Para Aclarar Borre laClav del Registro de la Siguiente Manera:

Set borrar = CreateObject("WScript.Shell")
borrar.RegDelete ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CLAVEABORRAR")

pero igual sirve y mientras sirva ta bien... ;D
eso es vbs.

;D Salu2, WarGhost
pure linux programming...

Rudy21

A De acuerdo Muchas Gracias,

Lo k Me Posteas Gorky es usando Apis vdd

a ok

y ¿Cual me recomiendan mas y Porque?

salu2


a P.D

Si uso VBS para poner en el registro lo detecta el NOD32, usando apis no lo detecta?? aunke descubri k si pongo el codigo de la residencia en un timer ya no lo detecta


salu2


WarGhost

exacto el vbs son mas detectados por los sistema de heristica.

;D Salu2, WarGhost
¿Qué culpa tengo yo de tener la sangre roja y el corazón a la izquierda?