≡ Menu

Delete Registry key from command line

Reg command allows us to delete registry keys and registry values from command line. This reg command can be used from batch files also. The syntax for the delete operation is explained below with examples.

Delete a registry value

reg delete  Registry_key_path /v Registry_value_name

Example:

Delete the registry value ‘CleanShutdown‘ under the key ‘HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer

c:\> reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v CleanShutdown
Delete the registry value CleanShutdown (Yes/No)? yes
The operation completed successfully.

If you want to delete registry key without being prompted for confirmation then add /f switch to the command.

reg delete  Registry_key_path /v Registry_value_name /f

Example:
For the above example, the command to delete the registry value without any confirmation prompt:

c:\> reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v CleanShutdown  /f
The operation completed successfully.

If the registry key has space in its name, you can use double quotes as below.

reg delete "Registry_key_path" /v Registry_value_name /f

Example:
Command to delete the registry value ‘TSAdvertise‘ under the registry key ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server’

reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v TSAdvertise /f

Delete a registry key

Delete all registry keys and values under a registry key:

reg delete Registry_key_path

Example:
Delete all the registry values under the key ‘HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites’

reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites

Delete all registry values under a registry key

 reg delete RegistryKey  /va
13 comments… add one
  • keanoosh

    thanks.

  • Ramesh

    Be sure to use the option ‘/f’ after the key as mentioned in the post. using it in wrong place errors out saying ‘invalid option’

    c:\>reg  /f  delete HKCU\SomeKey /v SomeValue
    ERROR: Invalid Argument/Option - '/f'.
    Type "REG /?" for usage.
    
    c:\>reg  delete /f HKCU\SomeKey /v SomeValue
    ERROR: Invalid key name.
    Type "REG DELETE /?" for usage.

    Correct usage is

    reg delete  HKCU\SomeKey /v SomeValue /f
  • mr_tg

    1) it works thanks

    c:\> reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v CleanShutdown
    Delete the registry value CleanShutdown (Yes/No)? yes
    The operation completed successfully.

    2) it does not work

    C:\>reg delete \\10.25.1.25\HkU\Software\Microsoft\Windows\CurrentVersion\Expl
    orer
    Error:  Отказано в доступе.

    (how to make it in remote pc , i know the password and user, if it is needed)

    • admin

      I think it implicitly tries to use the current logged in user credentials.
      Try doing net use to the remote host before running reg delete.

       net use \\10.25.1.25\C$  /u:domain\username
  • iulian

    How can I delete remote registry with space path?

    • admin

      Did you try enclosing it in quotes like below?

      reg delete "\\remotehost\hklm\some key with spaces\" /v regvalue
  • Jerry

    It’s working great base on your advice. Anyway, I still need to delete a registry key value with space, something example ‘Test This’ in
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

    Thanks in advance.
    Regards,

    • admin

      You can wrap the value name also in double quotes to make it work with space. For example the below command would work for the example case.

      C:\>reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run  /v "Test This"
      Delete the registry value Test This (Yes/No)? yes
      The operation completed successfully.
  • Jerry

    sorry, the value in space(key name with space), not key value

  • Brad

    Hi. What about a key that has quotes in the key name? I can’t get it to work, I don’t know how it expects me to escape the quotes.
    eg:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\”DropboxExt1″]

  • Erich

    ASUS laptop crashes on every boot. BSOD. tried f8, safe mode with command prompt; every option offered there starts and then returns to BSOD. MS repair says it “cannot make the necessary repairs”. Repair report says: “Registry is corrupt” Fix: “Registry rollback”. Laptop will not boot to CD/DVD drive, though I have used f12 to change boot config. The UBCD4WIN disk is useless there as well as all repair disks and Windows Repair disks. So I can’t fix corrupted registry with commands.
    So…I pulled the SATA drive, attached USB 2.0 interface cable, and am now trying to repair the registry from another windows (10) laptop. I open a CMD window and have the ASUS drive, (drive F) ready for the proper command sequence; if there is one. Or perhaps you know of a program on some website, that I can download to my Windows 10 laptop, that will do it for me.
    Option 2: re-format the drive and re-install it, and hope that the computer automatically re-installs Windows 7?
    Option 3: Fork over the money for a new windows 10 laptop?

    Any ideas?

    Thanks in advance for your help,

    Erich

  • Erich

    As a follow up to the previous post; I found MSIEXEC and wonder if that command can be used to perform an automatic registry repair?

    Thanks again,

  • Roberto Reynoso

    Thanks a lot for the fix and help. Will see if this error does not show again!

    Thanks,
    Roberto

Leave a Comment