Modifica

Condividi tramite


registry remove

Synopsis

Remove a registry key or value.

Important

The registry command and Microsoft.Windows/Registry resource are a proof-of-concept example for use with DSCv3. Don't use it in production.

Syntax

registry remove [Options] --key-path <KEY_PATH>

Description

The remove command deletes a registry key or value. The [Microsoft.Windows/Registry] resource uses this command for the Delete resource operation.

Examples

Example 1 - Remove a registry value

This example deletes the ExampleValue value on the HKCU\Example\Key registry key.

registry remove --key-path HKCU\Example\Key --value-name ExampleValue
{"timestamp":"2025-03-17T20:43:48.472328Z","level":"DEBUG","fields":{"message":"Remove key_path: HKCU\\Example\\Key, value_name: Some(\"ExampleValue\"), recurse: false"},"target":"registry","line_number":47}

Example 2 - Remove a registry key recursively

This example deletes the HKCU\ExampleKey registry key recursively. The command also deletes any subkeys or values of the HKCU\ExampleKey key.

registry remove --key-path HKCU\Example\Key --recurse
{"timestamp":"2025-03-17T20:44:13.597157Z","level":"DEBUG","fields":{"message":"Remove key_path: HKCU\\Example\\Key, value_name: None, recurse: true"},"target":"registry","line_number":47}

Options

-k, --key-path

Specifies the registry key path to remove. The path must start with a valid hive identifier. Each segment of the path must be separated by a backslash (\).

The following table describes the valid hive identifiers for the key path.

Short Name Long Name NT Path
HKCR HKEY_CLASSES_ROOT \Registry\Machine\Software\Classes\
HKCU HKEY_CURRENT_USER \Registry\User\<User SID>\
HKLM HKEY_LOCAL_MACHINE \Registry\Machine\
HKU HKEY_USERS \Registry\User\
HKCC HKEY_CURRENT_CONFIG \Registry\Machine\System\CurrentControlSet\Hardware Profiles\Current\
Type:      String
Mandatory: true

-v, --value-name

Defines the name of the value to remove for in the specified registry key path.

Type:      String
Mandatory: false

-r, --recurse

Indicates whether the command should recursively remove subkeys. By default, the command isn't recursive.

Type:      boolean
Mandatory: false

-h, --help

Displays the help for the current command or subcommand. When you specify this option, the application ignores all options and arguments after this one.

Type:      boolean
Mandatory: false