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

问题描述:

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

+0

正如@Shersha Fn指出的那样,您必须是管理员才能使用REG.EXE。有没有办法做到这一点作为非管理员,并避免“访问被拒绝”的消息? – 2017-03-15 18:21:08

可以使用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) 
+16

这个答案非常含糊,尽管它列出了所有可能性(这很好),但它不能清楚地回答OP的问题,不像@ nray的回答 – 2013-06-06 19:13:42

+0

链接断开.... – rjdkolb 2016-06-22 12:24:14

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

格式在这里:

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

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

是的,你可以使用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.exe来添加,删除或查询注册表值。 Reg.exe没有明确的修改命令,但可以通过删除然后添加来完成。

除reg.exe之外,我强烈建议您还检查一下powershell,它的注册表处理能力非常强大。

+0

必须首先在客户机上启用PowerShell脚本通过使用`Set-ExecutionPolicy`。我有一个批处理脚本,它修改注册表以将执行策略设置为RemoteSigned。好处是用户可以启用并运行PowerShell脚本,而无需输入任何命令。他们只需双击批处理文件即可。 – 2011-04-12 13:11:48

@Franci佩诺夫 - 修改是在意义上覆写/f可能的,例如

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

+1为/ f 我已经为此写了几个脚本,但没有/ f,这真是太痛苦了;需要我在那里运行脚本时键入“y + [return]” – amyassin 2012-02-16 11:45:52

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

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数据:实际数据,以存储为 “字符串”,整数等

/v值:值的名称例如ProgId

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

了解更多关于阅读,设置或删除注册表项和值,保存和恢复从一个.reg文件。从here