简体   繁体   English

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

[英]Is it possible to modify a registry entry via a .bat/.cmd script?

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

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

reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"

You can use the REG command. 您可以使用REG命令。 From http://www.ss64.com/nt/reg.html : 来自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)

Yes, you can script using the reg command. 是的,您可以使用reg命令编写脚本。 Example: 例:

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

This would create key HKEY_CURRENT_USER\\Software\\SomeProduct , and add a String value "v2.4.6" named "Version" to that key. 这将创建密钥HKEY_CURRENT_USER\\Software\\SomeProduct ,并向该密钥添加名为“Version”的字符串值“v2.4.6”。

reg /? has the details. 有详细信息。

This is how you can modify registry, without yes or no prompt and don't forget to run as administrator 这是你如何修改注册表,没有是或没有提示,不要忘记以管理员身份运行

reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc   /v Valuename /t REG_SZ /d valuedata  /f 

Below is a real example to set internet explorer as my default browser 下面是将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: Force an update without prompting "Value exists, overwrite Y/N" / f强制:强制更新而不提示“值存在,覆盖Y / N”

/d Data : The actual data to store as a "String", integer etc / d Data:要存储为“String”,整数等的实际数据

/v Value : The value name eg ProgId / v值:值名称,例如ProgId

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

Learn more about Read, Set or Delete registry keys and values, save and restore from a .REG file. 了解有关读取,设置或删除注册表项和值的详细信息,从.REG文件保存和还原。 from here 这里开始

You can make a .reg file and call start on it. 您可以创建一个.reg文件并在其上调用start。 You can export any part of the registry as a .reg file to see what the format is. 您可以将注册表的任何部分导出为.reg文件,以查看格式是什么。

Format here: 格式在这里:

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

This can be run on any Windows machine without installing other software. 这可以在任何Windows机器上运行而无需安装其他软件。

Yes. 是。 You can use reg.exe which comes with the OS to add, delete or query registry values. 您可以使用操作系统附带的reg.exe来添加,删除或查询注册表值。 Reg.exe does not have an explicit modify command, but you can do it by doing delete and then add. Reg.exe没有显式的修改命令,但您可以通过执行删除然后添加来执行此操作。

除了reg.exe之外,我强烈建议您查看一下powershell,它在注册表处理方面的能力更强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM