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

前端 未结 8 957
萌比男神i
萌比男神i 2020-12-04 12:12

Is it possible to modify a registry value (whether string or DWORD) via a .bat/.cmd script?

相关标签:
8条回答
  • 2020-12-04 12:34

    Yes, you can script using the reg command. 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.

    reg /? has the details.

    0 讨论(0)
  • 2020-12-04 12:43

    You can use the REG command. From 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)
    
    0 讨论(0)
  • 2020-12-04 12:45

    In addition to reg.exe, I highly recommend that you also check out powershell, its vastly more capable in its registry handling.

    0 讨论(0)
  • 2020-12-04 12:46

    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

    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"

    /d Data : The actual data to store as a "String", integer etc

    /v Value : The value name eg ProgId

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

    Learn more about Read, Set or Delete registry keys and values, save and restore from a .REG file. from here

    0 讨论(0)
  • 2020-12-04 12:47

    Yes. You can use reg.exe which comes with the OS to add, delete or query registry values. Reg.exe does not have an explicit modify command, but you can do it by doing delete and then add.

    0 讨论(0)
  • 2020-12-04 12:52

    @Franci Penov - modify is possible in the sense of overwrite with /f, eg

    reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
    
    0 讨论(0)
提交回复
热议问题