50

是否可以通过 .bat/.cmd 脚本修改注册表值(无论是字符串还是 DWORD)?

4

8 回答 8

112

@Franci Penov -在覆盖的意义上修改可能的,例如 /f

reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
于 2008-10-04T13:26:36.420 回答
41

您可以使用 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)
于 2008-09-24T21:54:20.847 回答
26

reg是的,您可以使用该命令编写脚本。例子:

reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6

这将创建 key HKEY_CURRENT_USER\Software\SomeProduct,并向该键添加一个名为“Version”的字符串值“v2.4.6”。

reg /?有详细信息。

于 2008-09-24T21:54:50.127 回答
13

这是您可以修改注册表的方式,无需提示是或否,并且不要忘记以管理员身份运行

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 Force:强制更新而不提示“值存在,覆盖 Y/N”

/d 数据:存储为“字符串”、整数等的实际数据

/v Value : 值名称,例如 ProgId

/t 数据类型:REG_SZ(默认)| REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ

了解有关读取、设置或删除注册表项和值、从 .REG 文件保存和恢复的更多信息。从这里

于 2016-05-29T15:41:40.173 回答
4

您可以制作一个 .reg 文件并在其上调用 start。您可以将注册表的任何部分导出为 .reg 文件以查看格式。

格式在这里:

http://support.microsoft.com/kb/310516

这可以在任何 Windows 机器上运行而无需安装其他软件。

于 2008-09-24T21:54:32.390 回答
1

是的。您可以使用操作系统自带的reg.exe来添加、删除或查询注册表值。Reg.exe 没有明确的修改命令,但您可以通过删除然后添加来完成。

于 2008-09-24T21:56:03.790 回答
1

除了 reg.exe,我强烈建议您还检查一下 powershell,它在注册表处理方面的功能要强大得多。

于 2008-09-24T22:23:39.217 回答
-2

http://www.chaminade.org/MIS/Articles/RegistryEdit.htm

于 2008-09-24T21:54:20.767 回答