¿Es posible modificar una entrada de registro a través de un script .bat / .cmd?
-
02-07-2019 - |
Pregunta
¿Es posible modificar un valor de registro (ya sea una cadena o DWORD) a través de un script .bat / .cmd?
Solución
Puedes usar el comando REG. Desde http://www.ss64.com/nt/reg.html :
Syntax:
REG QUERY [ROOT\]RegKey /v ValueName [/s]
REG QUERY [ROOT\]RegKey /ve --This returns the (default) value
REG ADD [ROOT\]RegKey /v ValueName [/t DataType] [/S Separator] [/d Data] [/f]
REG ADD [ROOT\]RegKey /ve [/d Data] [/f] -- Set the (default) value
REG DELETE [ROOT\]RegKey /v ValueName [/f]
REG DELETE [ROOT\]RegKey /ve [/f] -- Remove the (default) value
REG DELETE [ROOT\]RegKey /va [/f] -- Delete all values under this key
REG COPY [\\SourceMachine\][ROOT\]RegKey [\\DestMachine\][ROOT\]RegKey
REG EXPORT [ROOT\]RegKey FileName.reg
REG IMPORT FileName.reg
REG SAVE [ROOT\]RegKey FileName.hiv
REG RESTORE \\MachineName\[ROOT]\KeyName FileName.hiv
REG LOAD FileName KeyName
REG UNLOAD KeyName
REG COMPARE [ROOT\]RegKey [ROOT\]RegKey [/v ValueName] [Output] [/s]
REG COMPARE [ROOT\]RegKey [ROOT\]RegKey [/ve] [Output] [/s]
Key:
ROOT :
HKLM = HKey_Local_machine (default)
HKCU = HKey_current_user
HKU = HKey_users
HKCR = HKey_classes_root
ValueName : The value, under the selected RegKey, to edit.
(default is all keys and values)
/d Data : The actual data to store as a "String", integer etc
/f : Force an update without prompting "Value exists, overwrite Y/N"
\\Machine : Name of remote machine - omitting defaults to current machine.
Only HKLM and HKU are available on remote machines.
FileName : The filename to save or restore a registry hive.
KeyName : A key name to load a hive file into. (Creating a new key)
/S : Query all subkeys and values.
/S Separator : Character to use as the separator in REG_MULTI_SZ values
the default is "\0"
/t DataType : REG_SZ (default) | REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
Output : /od (only differences) /os (only matches) /oa (all) /on (no output)
Otros consejos
@Franci Penov - modificar es posible en el sentido de sobrescribir con / f
, por ejemplo,
reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
Sí, puede realizar una secuencia de comandos con el comando reg
.
Ejemplo:
reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
Esto crearía la clave HKEY_CURRENT_USER \ Software \ SomeProduct
, y agregaría un valor de cadena " v2.4.6 " nombre " Versión " a esa llave.
reg /?
tiene los detalles.
Esta es la forma en que puede modificar el registro, sin preguntar si o no, y no se olvide de ejecutar como administrador
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc /v Valuename /t REG_SZ /d valuedata /f
A continuación se muestra un ejemplo real para configurar Internet Explorer como mi navegador predeterminado
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice /v ProgId /t REG_SZ /d IE.HTTPS /f
/ f Force: forzar una actualización sin preguntar " El valor existe, sobrescribir S / N "
/ d Datos: los datos reales para almacenar como una " Cadena " ;, entero, etc.
/ v Valor: el nombre del valor, por ejemplo, ProgId
/ t DataType: REG_SZ (predeterminado) | REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
Obtenga más información acerca de Leer, establecer o eliminar claves y valores de registro, guardar y restaurar desde un archivo .REG. desde aquí
Puedes hacer un archivo .reg y llamar a start en él. Puede exportar cualquier parte del registro como un archivo .reg para ver cuál es el formato.
Formato aquí:
http://support.microsoft.com/kb/310516
Esto se puede ejecutar en cualquier máquina Windows sin instalar otro software.
Sí. Puede usar reg.exe que viene con el sistema operativo para agregar, eliminar o consultar valores de registro. Reg.exe no tiene un comando de modificación explícito, pero puede hacerlo haciendo eliminar y luego agregar.
Además de reg.exe, te recomiendo que también eches un vistazo a powershell, que es mucho más capaz de manejar el registro.