Skip to content
Tcl Source Code Artifact [67c76071fd]
Login

Artifact [67c76071fd]

Artifact 67c76071fd5a1313d2dff88817ba10f95b4f503a4233c2d709e929948ad573ac:



CommandName: registry ManualSection: n Version: 1.1 TclPart: registry TclDescription: Tcl Bundled Packages Keywords:

Name

registry - Manipulate the Windows registry

Synopsis

::: {.synopsis} ::: [package]{.cmd} [require]{.sub} [registry]{.lit} [1.4]{.lit}

[registry]{.cmd} [-mode]{.optarg} [option]{.arg} [keyName]{.arg} [arg arg]{.optdot} :::

Description

The fBregistryfR package provides a general set of operations for manipulating the Windows registry. The package implements the fBregistryfR Tcl command. This command is only supported on the Windows platform. Warning: this command should be used with caution as a corrupted registry can leave your system in an unusable state.

KeyName is the name of a registry key. Registry keys must be one of the following forms:

\***hostname*rootname**keypath

rootname****keypath

rootname

Hostname specifies the name of any valid Windows host that exports its registry. The fIrootnamefR component must be one of fBHKEY_LOCAL_MACHINEfR, fBHKEY_USERSfR, fBHKEY_CLASSES_ROOTfR, fBHKEY_CURRENT_USERfR, fBHKEY_CURRENT_CONFIGfR, fBHKEY_PERFORMANCE_DATAfR, or fBHKEY_DYN_DATAfR. The fIkeypathfR can be one or more registry key names separated by backslash (fB\fR) characters.

The optional fI-modefR argument indicates which registry to work with; when it is fB-32bitfR the 32-bit registry will be used, and when it is fB-64bitfR the 64-bit registry will be used. If this argument is omitted, the system's default registry will be the subject of the requested operation.

Option indicates what to do with the registry key name. Any unique abbreviation for fIoptionfR is acceptable. The valid options are:

registry broadcast fIkeyNamefR ?fB-timeoutfR fImillisecondsfR? : Sends a broadcast message to the system and running programs to notify them of certain updates. This is necessary to propagate changes to key registry keys like Environment. The timeout specifies the amount of time, in milliseconds, to wait for applications to respond to the broadcast message. It defaults to 3000. The following example demonstrates how to add a path to the global Environment and notify applications of the change without requiring a logoff/logon step (assumes admin privileges):

```
set regPath [join {
    HKEY_LOCAL_MACHINE
    SYSTEM
    CurrentControlSet
    Control
    {Session Manager}
    Environment
} "\\"]
set curPath [registry get $regPath "Path"]
registry set $regPath "Path" "$curPath;$addPath"
registry broadcast "Environment"
```

registry delete fIkeyNamefR ?fIvalueNamefR? : If the optional fIvalueNamefR argument is present, the specified value under fIkeyNamefR will be deleted from the registry. If the optional fIvalueNamefR is omitted, the specified key and any subkeys or values beneath it in the registry hierarchy will be deleted. If the key could not be deleted then an error is generated. If the key did not exist, the command has no effect.

registry get fIkeyName valueNamefR : Returns the data associated with the value fIvalueNamefR under the key fIkeyNamefR. If either the key or the value does not exist, then an error is generated. For more details on the format of the returned data, see fBSUPPORTED TYPESfR, below.

registry keys fIkeyNamefR ?fIpatternfR? : If fIpatternfR is not specified, returns a list of names of all the subkeys of fIkeyNamefR. If fIpatternfR is specified, only those names matching fIpatternfR are returned. Matching is determined using the same rules as for fBstring matchfR. If the specified fIkeyNamefR does not exist, then an error is generated.

registry set fIkeyNamefR ?fIvalueName datafR ?fItypefR?? : If fIvalueNamefR is not specified, creates the key fIkeyNamefR if it does not already exist. If fIvalueNamefR is specified, creates the key fIkeyNamefR and value fIvalueNamefR if necessary. The contents of fIvalueNamefR are set to fIdatafR with the type indicated by fItypefR. If fItypefR is not specified, the type fBszfR is assumed. For more details on the data and type arguments, see fBSUPPORTED TYPESfR below.

registry type fIkeyName valueNamefR : Returns the type of the value fIvalueNamefR in the key fIkeyNamefR. For more information on the possible types, see fBSUPPORTED TYPESfR, below.

registry values fIkeyNamefR ?fIpatternfR? : If fIpatternfR is not specified, returns a list of names of all the values of fIkeyNamefR. If fIpatternfR is specified, only those names matching fIpatternfR are returned. Matching is determined using the same rules as for fBstring matchfR.

Supported types

Each value under a key in the registry contains some data of a particular type in a type-specific representation. The fBregistryfR command converts between this internal representation and one that can be manipulated by Tcl scripts. In most cases, the data is simply returned as a Tcl string. The type indicates the intended use for the data, but does not actually change the representation. For some types, the fBregistryfR command returns the data in a different form to make it easier to manipulate. The following types are recognized by the registry command:

binary : The registry value contains arbitrary binary data. The data is represented exactly in Tcl, including any embedded nulls.

none : The registry value contains arbitrary binary data with no defined type. The data is represented exactly in Tcl, including any embedded nulls.

sz : The registry value contains a null-terminated string. The data is represented in Tcl as a string.

expand_sz : The registry value contains a null-terminated string that contains unexpanded references to environment variables in the normal Windows style (for example, "%PATH%"). The data is represented in Tcl as a string.

dword : The registry value contains a little-endian 32-bit number. The data is represented in Tcl as a decimal string.

dword_big_endian : The registry value contains a big-endian 32-bit number. The data is represented in Tcl as a decimal string.

link : The registry value contains a symbolic link. The data is represented exactly in Tcl, including any embedded nulls.

multi_sz : The registry value contains an array of null-terminated strings. The data is represented in Tcl as a list of strings.

resource_list : The registry value contains a device-driver resource list. The data is represented exactly in Tcl, including any embedded nulls.

In addition to the symbolically named types listed above, unknown types are identified using a 32-bit integer that corresponds to the type code returned by the system interfaces. In this case, the data is represented exactly in Tcl, including any embedded nulls.

Portability issues

The registry command is only available on Windows.

Example

Print out how double-clicking on a Tcl script file will invoke a Tcl interpreter:

package require registry
set ext .tcl

# Read the type name
set type [registry get HKEY_CLASSES_ROOT\\$ext {}]
# Work out where to look for the command
set path HKEY_CLASSES_ROOT\\$type\\Shell\\Open\\command
# Read the command!
set command [registry get $path {}]

puts "$ext opens with $command"