registry(n)
πΈ NAME πΈ
registry β manipulating the Windows registry, bestie π
β¨ SYNOPSIS β¨
package require registry 1.3
registry ?-mode? option keyName ?arg arg ...?
π DESCRIPTION π
Okay so. The registry package hands you a whole general set of operations for manipulating the Windows registry. It implements the registry Tcl command. And listen β this command is only supported on the Windows platform. That's it, that's the whole platform situation, no cap.
β οΈ Warning: this command should be used with caution, bestie, because a corrupted registry can leave your system in an unusable state π Not "a little broken". Unusable. Be gentle with it.
KeyName is the name of a registry key. Registry keys have to be one of these forms:
\\hostname\rootname\keypath
rootname\keypath
rootname
Hostname is the name of any valid Windows host that exports its registry. The rootname component must be one of HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, or HKEY_DYN_DATA. And the keypath can be one or more registry key names separated by backslash (\) characters. Periodt.
The optional -mode argument tells you which registry you're working with β when it's -32bit, the 32-bit registry gets used, and when it's -64bit, the 64-bit registry gets used. If you just... don't pass this argument at all? Then the system's default registry is the subject of the requested operation. Chill.
Option is what to do with the registry key name. Any unique abbreviation for option is acceptable β abbreviate away, it's fine π«Ά. The valid options are:
registry broadcast keyName ?-timeout milliseconds?β 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 likeEnvironment. The timeout specifies the amount of time, in milliseconds, to wait for applications to respond to the broadcast message. It defaults to3000. 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 keyName ?valueName?β if the optional valueName argument is present, the specified value under keyName gets deleted from the registry. If the optional valueName is omitted, the specified key and any subkeys or values beneath it in the registry hierarchy get deleted π³. If the key could not be deleted, then an error is generated. If the key did not exist, the command has no effect. Nothing happens. Silence. Iconic.registry get keyName valueNameβ returns the data associated with the value valueName under the key keyName. 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 SUPPORTED TYPES, below.registry keys keyName ?pattern?β if pattern is not specified, returns a list of names of all the subkeys of keyName. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as forstring match. If the specified keyName does not exist, then an error is generated.registry set keyName ?valueName data ?type??β if valueName is not specified, creates the key keyName if it does not already exist. If valueName is specified, creates the key keyName and value valueName if necessary. The contents of valueName are set to data with the type indicated by type. If type is not specified, the typeszis assumed. For more details on the data and type arguments, see SUPPORTED TYPES below.registry type keyName valueNameβ returns the type of the value valueName in the key keyName. For more information on the possible types, see SUPPORTED TYPES, below.registry values keyName ?pattern?β if pattern is not specified, returns a list of names of all the values of keyName. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as forstring match.
π¦ SUPPORTED TYPES π¦
Every value under a key in the registry contains some data of a particular type, in a type-specific representation. The registry command converts between that internal representation and one that Tcl scripts can actually manipulate. In most cases, the data is simply returned as a Tcl string. The type indicates the intended use for the data, but it does not actually change the representation. For some types though, the registry command returns the data in a different form to make it easier to manipulate. Here are the types the registry command recognizes:
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.
And on top of all those symbolically named types? Unknown types get identified using a 32-bit integer that corresponds to the type code returned by the system interfaces. In that case, the data is represented exactly in Tcl, including any embedded nulls. π
π PORTABILITY ISSUES π
The registry command is only available on Windows. That's the whole section. That's it. πͺ
π 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"
π KEYWORDS π
registry
And that's the whole page, bestie!! π This one ships as part of the Tcl Bundled Packages and it's version 1.1 of registry(n) β so go forth, poke at the Windows registry, and please don't break your machine, I am begging πβ¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1997 Sun Microsystems, Inc
- Copyright (c) 2002 ActiveState Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms