Hola estoy intentando hacer un programa que busque una clave en el registro y al encontrarla, borrar la subclave y todas las claves que haya dentro de donde se encuentre. Un saludo y muchas gracias
¿Que tienes hecho ? ¿Cual es la duda? :P
No son todas pero con esas puedes hacer lo que deseas y un poco mas
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, ByRef phkResult As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Long
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, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByRef phkResult As Long, ByRef lpdwDisposition As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByRef lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, ByRef lpcbClass As Long, ByRef lpftLastWriteTime As FILETIME) As Long
Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, ByRef lpcbValueName As Long, ByVal lpReserved As Long, ByRef lpType As Long, ByRef lpData As Byte, ByRef lpcbData As Long) As Long
Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegGetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, ByRef pSecurityDescriptor As SECURITY_DESCRIPTOR, ByRef lpcbSecurityDescriptor As Long) As Long
Declare Function RegInstall Lib "advpack.dll" (ByVal hm As Long, ByVal pszSection As String, ByRef pstTable As CSTRTABLE) As Long
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
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
Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, lpSecurityAttributes As Any) As Long
Dulces Lunas
Se como buscar una clave en cuestio sabiendo donde esta. Pero si nose donde la guarda nose como buscarla.
Ejemplo:
On Error Resume Next
Set zonavirus = CreateObject("WScript.Shell")
X = zonavirus.regRead ("HKEY_LOCAL_MACHINE\Software\Encuentra")
If X = "uno" Then
MsgBox "Encontrado la variable"
Else
MsgBox "No encuentra la variable"
End If
Esto es un ejemplo de cuando se donde esta la clave, pero si quiero buscar en el registro un valor y nose donde se encuentra, que hago. En este caso "uno" esta en Encuentra, pero si no se que esta ahi, como puedo buscarlo en todo el registro.
Para encontrar un valor en el registro sigue estos pasos :
- Lista todas las claves del registro
- Lee todas las subclaves ( o no me acuerdo como se llaman las que tienen datos )
- Usa Instr para comprobar si existe la string dentro de la SubClave
;)
Me pones un ejemplo?
Hola, EnumRegistryKeys y CheckRegistryKey en el modulo 1.
http://foro.elhacker.net/programacion_vb/serial_y_unidad_de_pen_drive-t251332.0.html;msg1268382#msg1268382 (http://foro.elhacker.net/programacion_vb/serial_y_unidad_de_pen_drive-t251332.0.html;msg1268382#msg1268382)
S2
Y como es una vez encontrado, borrar la clave y la clave principal. si esta llena se puede borrar?
Me estoy mareando con tantas letras, jejeje. Es lo que tiene cuando te mandan hacer un programa para el trabajo y no tener ni idea de programacion en vbs. Desesperacion total....
Paso a paso, dicenn
Cita de: canario77 en 4 Octubre 2009, 13:46 PM
Y como es una vez encontrado, borrar la clave y la clave principal. si esta llena se puede borrar?
RegDeleteKey(Raiz,Clave)
http://www.google.com.ar/search?hl=es&q=RegDeleteKey&btnG=Buscar&meta= (http://www.google.com.ar/search?hl=es&q=RegDeleteKey&btnG=Buscar&meta=)
S2
Una ultima cosa. Yo busco un valor de una clave, y al encontrarla como puedo borrar el contenido de esa clave, sin saber de antemano su nombre.
Ejemplo:
busco defaultuser y la encuentra en HKLM\Software\microsofot\Winnt\CurrentVersion\User como guardo la clave User para luego borrarlo.
La almacenás en en una variable, como en la funcion Datos del primer link que te dejé.
¿cual es la variable que lo guarda?
Citar
- Lista todas las claves del registro
- Lee todas las subclaves ( o no me acuerdo como se llaman las que tienen datos )
- Usa Instr para comprobar si existe la string dentro de la SubClave
Cita de: canario77 en 4 Octubre 2009, 11:36 AM
Me pones un ejemplo?
EnumRegistryKeys y CheckRegistryKey Es un ejemplo de como enumerar claves y guardarlas en la funcion Datos,
debes adaptarlo a lo que vos nesecites. Luego para borrar RegDeleteKey.
Saludos
Se pueden poner comodines en el codigo, es decir, como siempre la clave es aleatoria, se podria poner HKLM\Software\Miscrosoft\Windows NT\Current Version\ProfileList\* ya que donde pone * a veces es S-1-51 otras veces S-1-20, etc etc
Option Explicit
Private 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) 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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal numBytes As Long)
Private Const KEY_READ = &H20019
Private Const KEY_ALL_ACCESS = &H3F
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
Const ERROR_MORE_DATA = 234
Function GetRegistryValue(ByVal hKey As Long, ByVal KeyName As String, _
ByVal ValueName As String, Optional DefaultValue As Variant) As Variant
Dim handle As Long
Dim resLong As Long
Dim resString As String
Dim resBinary() As Byte
Dim length As Long
Dim retVal As Long
Dim valueType As Long
' Prepare the default result
GetRegistryValue = IIf(IsMissing(DefaultValue), Empty, DefaultValue)
' Open the key, exit if not found.
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) Then
Exit Function
End If
' prepare a 1K receiving resBinary
length = 1024
ReDim resBinary(0 To length - 1) As Byte
' read the registry key
retVal = RegQueryValueEx(handle, ValueName, 0, valueType, resBinary(0), _
length)
' if resBinary was too small, try again
If retVal = ERROR_MORE_DATA Then
' enlarge the resBinary, and read the value again
ReDim resBinary(0 To length - 1) As Byte
retVal = RegQueryValueEx(handle, ValueName, 0, valueType, resBinary(0), _
length)
End If
' return a value corresponding to the value type
Select Case valueType
Case REG_DWORD
CopyMemory resLong, resBinary(0), 4
GetRegistryValue = resLong
Case REG_SZ, REG_EXPAND_SZ
' copy everything but the trailing null char
resString = Space$(length - 1)
CopyMemory ByVal resString, resBinary(0), length - 1
GetRegistryValue = resString
Case REG_BINARY
' resize the result resBinary
If length <> UBound(resBinary) + 1 Then
ReDim Preserve resBinary(0 To length - 1) As Byte
End If
GetRegistryValue = resBinary()
Case REG_MULTI_SZ
' copy everything but the 2 trailing null chars
resString = Space$(length - 2)
CopyMemory ByVal resString, resBinary(0), length - 2
GetRegistryValue = resString
Case Else
RegCloseKey handle
Err.Raise 1001, , "Unsupported value type"
End Select
' close the registry key
RegCloseKey handle
End Function
Function EnumRegistryKeys(ByVal hKey As Long, ByVal KeyName As String) As Collection
'Enumerate registry keys under a given key 'Returns a collection of strings
Dim handle As Long
Dim length As Long
Dim index As Long
Dim subkeyName As String
' initialize the result collection
Set EnumRegistryKeys = New Collection
' Open the key, exit if not found
If Len(KeyName) Then
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) Then Exit Function
' in all case the subsequent functions use hKey
hKey = handle
End If
Do
' this is the max length for a key name
length = 260
subkeyName = Space$(length)
' get the N-th key, exit the loop if not found
If RegEnumKey(hKey, index, subkeyName, length) Then Exit Do
' add to the result collection
subkeyName = Left$(subkeyName, InStr(subkeyName, vbNullChar) - 1)
EnumRegistryKeys.Add subkeyName, subkeyName
' prepare to query for next key
index = index + 1
Loop
' Close the key, if it was actually opened
If handle Then RegCloseKey handle
End Function
Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As Boolean
' Return True if a Registry key exists
Dim handle As Long
' Try to open the key
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
' The key exists
CheckRegistryKey = True
' Close it before exiting
RegCloseKey handle
End If
End Function
Private Sub Form_Load()
Dim i As Long
Dim variable As String
If EnumRegistryKeys(&H80000002, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList").Count > 0 Then
For i = 1 To EnumRegistryKeys(&H80000002, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList").Count
variable = variable + EnumRegistryKeys(&H80000002, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList").Item(i) + vbNewLine
Next i
MsgBox variable
Else
MsgBox "No"
End If
End
End Sub
Lo que quiero buscar es la clave CentralProfile.
Cita de: YST en 4 Octubre 2009, 01:51 AM
Para encontrar un valor en el registro sigue estos pasos :
- Lista todas las claves del registro
- Lee todas las subclaves ( o no me acuerdo como se llaman las que tienen datos )
- Usa Instr para comprobar si existe la string dentro de la SubClave
canario77 : Ya te han indicado los pasos a seguir
@ canario77
el post no da para preguntar mas, ya te dijeron todo lo que hay que hacer, ahora de tu parte debes poner ganas para hacer las cosas y buscar un poco mas en internet antes o en el mismo foro...
saludos.