是否可以通过.bat / .cmd脚本修改注册表项?
-
02-07-2019 - |
题
是否可以通过.bat / .cmd脚本修改注册表值(无论是字符串还是DWORD)?
解决方案
您可以使用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 "\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)
其他提示
@Franci Penov - 使用 / f
修改覆盖意义上的 ,例如
reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
是的,您可以使用 reg
命令编写脚本。
例如:
reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
这将创建密钥 HKEY_CURRENT_USER \ Software \ SomeProduct
,并添加字符串值“v2.4.6”。命名为“版本”那把钥匙。
reg /?
有详细信息。
这是如何修改注册表,没有是或没有提示,不要忘记以管理员身份运行
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc /v Valuename /t REG_SZ /d valuedata /f
以下是将Internet Explorer设置为我的默认浏览器的真实示例
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice /v ProgId /t REG_SZ /d IE.HTTPS /f
/ f强制:强制更新而不提示“值存在,覆盖 Y / N"
/ d数据:要存储为“String”,整数等的实际数据
/ v值:值名称,例如ProgId
/ t DataType:REG_SZ(默认值)| REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
了解有关读取,设置或删除注册表项和值的详细信息,从.REG文件保存和还原。来自此处
您可以创建.reg文件并在其上调用start。您可以将注册表的任何部分导出为.reg文件,以查看格式是什么。
格式在这里:
http://support.microsoft.com/kb/310516
这可以在任何Windows计算机上运行而无需安装其他软件。
是。您可以使用操作系统附带的reg.exe来添加,删除或查询注册表值。 Reg.exe没有明确的修改命令,但您可以通过删除然后添加来执行此操作。
除了reg.exe之外,我强烈建议您查看一下PowerShell,它在注册表处理方面的能力更强。