是否可以通过.bat/.cmd脚本修改注册表项?

Bri*_*ndy 45 windows registry automation cmd batch-file

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

nra*_*ray 101

@Franci佩诺夫-修改可能的意识覆盖/f,如

reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
Run Code Online (Sandbox Code Playgroud)

  • 为/ f我写了几个脚本,但没有/ f它是如此痛苦; 要求我在运行脚本时输入"y + [return]" (12认同)
  • 谢谢.这应该是接受的答案,因为它解释了如何修改现有的KEY. (10认同)

Rui*_*ira 38

您可以使用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)
Run Code Online (Sandbox Code Playgroud)

  • 这个答案非常模糊,即使它列出了所有的可能性(这很好)但它不能清楚地回答OP的问题,不像@nray的回答 (19认同)

Fac*_*tic 26

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

reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
Run Code Online (Sandbox Code Playgroud)

这将创建密钥HKEY_CURRENT_USER\Software\SomeProduct,并向该密钥添加名为"Version"的字符串值"v2.4.6".

reg /? 有详细信息.


She*_* Fn 11

这是你如何修改注册表,没有是或没有提示,不要忘记以管理员身份运行

reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc   /v Valuename /t REG_SZ /d valuedata  /f 
Run Code Online (Sandbox Code Playgroud)

下面是将Internet Explorer设置为我的默认浏览器的真实示例

reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice   /v ProgId /t REG_SZ /d IE.HTTPS  /f 
Run Code Online (Sandbox Code Playgroud)

/ f强制:强制更新而不提示"值存在,覆盖Y/N"

/ d Data:要存储为"String",整数等的实际数据

/ v值:值名称,例如ProgId

/ t DataType:REG_SZ(默认值)| REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ

了解有关读取,设置或删除注册表项和值的详细信息,从.REG文件保存和还原.从这里开始


Lou*_*nco 5

您可以创建一个 .reg 文件并对其调用 start 。您可以将注册表的任何部分导出为 .reg 文件以查看格式是什么。

此处格式:

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

它可以在任何 Windows 计算机上运行,​​无需安装其他软件。