是否可以通过.bat / .cmd脚本修改注册表项?
时间:2020-03-06 14:41:30 来源:igfitidea点击:
是否可以通过.bat / .cmd脚本修改注册表值(字符串或者DWORD)?
解决方案
参见http://www.chaminade.org/MIS/Articles/RegistryEdit.htm
我们可以使用REG命令。从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 "reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
"
/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)
我们可以制作一个.reg文件,然后在其上调用start。我们可以将注册表的任何部分导出为.reg文件,以查看格式是什么。
在这里格式化:
http://support.microsoft.com/kb/310516
它可以在任何Windows计算机上运行,而无需安装其他软件。
是的,我们可以使用reg命令编写脚本。
例子:
reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
这将创建键" HKEY_CURRENT_USER \ Software \ SomeProduct",并向该键添加名为" Version"的字符串值" v2.4.6"。
reg /?有详细信息。
是的。我们可以使用操作系统随附的reg.exe来添加,删除或者查询注册表值。 Reg.exe没有显式的Modify命令,但是我们可以通过删除然后添加来完成。
除了reg.exe,我强烈建议我们也检查一下powershell,它在注册表处理方面的功能要强大得多。
@Franci Penov修改可以用/ f覆盖,例如

