Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Proyecto AjpdSoft: Foros

AjpdSoft :: Ver tema - Escribir en el registro (regedit) con VBScript
Foros de discusión Buscar Perfil FAQ Iniciar sesión
Information Escribir en el registro (regedit) con VBScript

Publicar nuevo tema Responder al tema
Foros de discusión » VB.Net, C# .Net, Visual Studio .Net   
Ver tema anterior :: Ver tema siguiente
AutorMensaje
varios
Magnífico usuario


Registrado: Oct 10, 2006
Mensajes: 2092

Asunto: Escribir en el registro (regedit) con VBScript Responder citando

¿Se puede crear un valor de cadena en una clave del registro de configuraciones (regedit) de Windows 7 mediante VBScript?
MensajePublicado:
Sab Sep 11, 2010 12:52 pm
Top of PageVer perfil de usuario
alonsojpd
Administrador/Moderador


Registrado: Sep 16, 2003
Mensajes: 2687

Asunto: Re: Escribir en el registro (regedit) con VBScript Responder citando



Anuncios



varios escribió:
¿Se puede crear un valor de cadena en una clave del registro de configuraciones (regedit) de Windows 7 mediante VBScript?


Puedes usar este código VBScript:

Código:

Const HKEY_CURRENT_USER = &H80000001

equipo = "."
Set StdOut = WScript.StdOut

Set oReg = GetObject("winmgmts:{impersonationLevel=" & _
    "impersonate}!\\" & _
    equipo & "\root\default:StdRegProv")

claveRegistro = "Software\AjpdSoft\Gestión de transportes"
nombreValorCadena = "Versión"
valorCadena = "VBScript creación o modificación valor cadena"
oReg.SetStringValue HKEY_CURRENT_USER, claveRegistro, _
    nombreValorCadena, valorCadena


Donde:
* "claveRegistro": subclaves del registro donde se creará el valor de cadena.
* "nombreValorCadena ": nombre del valor de cadena que se creará si no existe o se modificará si existe con el valor indicado en "valorCadena"
* HKEY_CURRENT_USER: rama del registro (clave principal), para otras claves:

Código:

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
MensajePublicado:
Sab Sep 11, 2010 12:54 pm
Top of PageVer perfil de usuario
varios
Magnífico usuario


Registrado: Oct 10, 2006
Mensajes: 2092

Asunto: Re: Escribir en el registro (regedit) con VBScript Responder citando



Anuncios



Ok, funciona pero ¿cómo lo hago para escribir en un valor DWORD en vez de un valor de Cadena?
MensajePublicado:
Sab Sep 11, 2010 1:12 pm
Top of PageVer perfil de usuario
alonsojpd
Administrador/Moderador


Registrado: Sep 16, 2003
Mensajes: 2687

Asunto: Re: Escribir en el registro (regedit) con VBScript Responder citando



Anuncios



varios escribió:
Ok, funciona pero ¿cómo lo hago para escribir en un valor DWORD en vez de un valor de Cadena?


Para crear un valor DWORD (o modificar el valor de uno existente), puedes usar este código VBScript:

Código:

Const HKEY_LOCAL_MACHINE = &H80000002

equipo = "."
Set StdOut = WScript.StdOut

Set oReg = GetObject("winmgmts:" &_
    "{impersonationLevel=impersonate}!\\" &_
    equipo & "\root\default:StdRegProv")

claveRegistro = "SYSTEM\CurrentControlSet\Services\Cdrom"
nombreValorDWord = "AutoRun"
valorDWORD = 0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE, claveRegistro, _
    nombreValorDWord, valorDWORD
MensajePublicado:
Sab Sep 11, 2010 1:13 pm
Top of PageVer perfil de usuario
varios
Magnífico usuario


Registrado: Oct 10, 2006
Mensajes: 2092

Asunto: Re: Escribir en el registro (regedit) con VBScript Responder citando



Anuncios



Por seguir con este tema ¿cómo puedo hacer otras acciones en el registro con VBScript como por ejemplo monitorizar cambios en el registro o crear claves o eliminar claves?
MensajePublicado:
Sab Sep 11, 2010 1:28 pm
Top of PageVer perfil de usuario
alonsojpd
Administrador/Moderador


Registrado: Sep 16, 2003
Mensajes: 2687

Asunto: Re: Escribir en el registro (regedit) con VBScript Responder citando



Anuncios



varios escribió:
Por seguir con este tema ¿cómo puedo hacer otras acciones en el registro con VBScript como por ejemplo monitorizar cambios en el registro o crear claves o eliminar claves?


Aquí tienes algunas acciones que se pueden realizar con VBScript con respecto al registro de configuraciones de Windows 7 mediante WMI:

Comprobar los permisos de acceso al registro:

Código:

const KEY_QUERY_VALUE = &H0001
const KEY_SET_VALUE = &H0002
const KEY_CREATE_SUB_KEY = &H0004
const DELETE = &H00010000


const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet"


oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Query Value Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Query Value Access Rights on Key"
End If   

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Set Value Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Set Value Access Rights on Key"
End If   

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_CREATE_SUB_KEY, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Create SubKey Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Create SubKey Access Rights on Key"
End If

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, DELETE, bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Delete Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Delete Access Rights on Key"
End If


Crear una clave de registro:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath


Crear valores de cadena y DWORD:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "String Value Name"
strValue = "string value"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "DWORD Value Name"
dwValue = 82
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue


Eliminar una clave de registro:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"

oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath


Eliminar valores de registro:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strDWORDValueName = "DWORD Value Name"
strExpandedStringValueName = "Expanded String Value Name"
strMultiStringValueName = "Multi String Value Name"
strStringValueName = "String Value Name"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName


Mostrar propiedades del registro:

Código:

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Registry")
For Each objItem in colItems
    Wscript.Echo "Current Size: " & objItem.CurrentSize
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Install Date: " & objItem.InstallDate
    Wscript.Echo "Maximum Size: " & objItem.MaximumSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Proposed Size: " & objItem.ProposedSize
Next


Mostrar los posibles valores y tipos del registro:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\Lsa"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
arrValueNames, arrValueTypes

For i=0 To UBound(arrValueNames)
    StdOut.WriteLine "Value Name: " & arrValueNames(i)
   
    Select Case arrValueTypes(i)
        Case REG_SZ
            StdOut.WriteLine "Data Type: String"
            StdOut.WriteBlankLines(1)
        Case REG_EXPAND_SZ
            StdOut.WriteLine "Data Type: Expanded String"
            StdOut.WriteBlankLines(1)
        Case REG_BINARY
            StdOut.WriteLine "Data Type: Binary"
            StdOut.WriteBlankLines(1)
        Case REG_DWORD
            StdOut.WriteLine "Data Type: DWORD"
            StdOut.WriteBlankLines(1)
        Case REG_MULTI_SZ
            StdOut.WriteLine "Data Type: Multi String"
            StdOut.WriteBlankLines(1)
    End Select
Next


Monitorizar eventos de registro:

Código:

Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

wmiServices.ExecNotificationQueryAsync wmiSink, _
  "SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & _
      "AND KeyPath='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'" _
          & " AND ValueName='CSDVersion'"

WScript.Echo "Listening for Registry Change Events..." & vbCrLf

While(1)
    WScript.Sleep 1000
Wend

Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" & vbCrLf & _
                 "------------------------------" & vbCrLf & _
                 wmiObject.GetObjectText_()
End Sub


Monitorizar eventos en subclave de registro:

Código:

Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")


wmiServices.ExecNotificationQueryAsync wmiSink, _
  "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND " & _
    "KeyPath='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'"

WScript.Echo "Listening for Registry Change Events..." & vbCrLf

While(1)
    WScript.Sleep 1000
Wend

Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" & vbCrLf & _
                 "------------------------------" & vbCrLf & _
                 wmiObject.GetObjectText_()
End Sub


Leer un valor binario de registro:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "LicenseInfo"
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue


For i = lBound(strValue) to uBound(strValue)
    StdOut.WriteLine  strValue(i)
Next


Leer un valor multistring:

Código:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\Eventlog\System"
strValueName = "Sources"
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,arrValues

For Each strValue In arrValues
    StdOut.WriteLine  strValue
Next


Leer un valor string o dword:

Código:

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "Console"
strValueName = "HistoryBufferSize"
oReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
StdOut.WriteLine "Current History Buffer Size: " & dwValue


strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
strValueName = "TrustPolicy"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
StdOut.WriteLine "Current WSH Trust Policy Value: " & strValue
MensajePublicado:
Sab Sep 11, 2010 1:54 pm
Top of PageVer perfil de usuario
Mostrar mensajes de anteriores:   
Todas las horas son GMT - 1 Horas
Publicar nuevo tema Responder al tema
Foros de discusión » VB.Net, C# .Net, Visual Studio .Net  

Cambiar a:  
Key
  Puede publicar nuevos temas en este foro
No puede responder a temas en este foro
No puede editar sus mensajes en este foro
No puede borrar sus mensajes en este foro
No puede votar en encuestas en este foro
Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A