È possibile modificare una voce di registro tramite uno script .bat / .cmd?
-
02-07-2019 - |
Domanda
È possibile modificare un valore di registro (sia esso stringa o DWORD) tramite uno script .bat / .cmd?
Soluzione
È possibile utilizzare il comando REG. Da 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)
Altri suggerimenti
@Franci Penov - modificare è nel senso di sovrascrivi con / f
, ad es.
reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
Sì, puoi eseguire lo script utilizzando il comando reg
.
Esempio:
reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
Ciò creerebbe la chiave HKEY_CURRENT_USER \ Software \ SomeProduct
e aggiungerebbe un valore String " v2.4.6 " denominato " Versione " a quella chiave.
reg /?
ha i dettagli.
Ecco come è possibile modificare il registro, senza prompt sì o no e non dimenticare di eseguire come amministratore
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc /v Valuename /t REG_SZ /d valuedata /f
Di seguito è riportato un esempio reale per impostare Internet Explorer come browser predefinito
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice /v ProgId /t REG_SZ /d IE.HTTPS /f
/ f Force: forza un aggiornamento senza richiedere " esiste un valore, sovrascrivi Y / N "
/ d Dati: i dati effettivi da archiviare come " String " ;, integer etc
/ v Valore: il nome del valore, ad esempio ProgId
/ t Tipo di dati: REG_SZ (impostazione predefinita) | REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
Ulteriori informazioni su Leggi, Imposta o Elimina chiavi e valori di registro, salva e ripristina da un file .REG. da qui
Puoi creare un file .reg e chiamarlo su di esso. Puoi esportare qualsiasi parte del registro come file .reg per vedere qual è il formato.
Formatta qui:
http://support.microsoft.com/kb/310516
Questo può essere eseguito su qualsiasi macchina Windows senza installare altro software.
Sì. È possibile utilizzare reg.exe fornito con il sistema operativo per aggiungere, eliminare o eseguire query sui valori del registro. Reg.exe non ha un comando esplicito di modifica, ma puoi farlo eliminando e quindi aggiungendo.
Oltre a reg.exe, consiglio vivamente di provare anche PowerShell, che è di gran lunga più capace nella sua gestione del registro.