regset Tcl Command

NAME

regset - Manage the Windows NT Environment registry

SYNOPSIS

dmh::regset ?switches? varname ?value?

dmh::regset -enum ?{ -machine_env | -user_env }?

dmh::regset -announce


DESCRIPTION

This command is used to work with environment variables in the Windows NT registry. These environment variables are persistent; having been set, they are set for subsequent processes and future computing sessions. Similar behavior is obtained on Posix platforms by editing the profile scripts that are invoked for every user, or for the individual user.

The optional ?value? term is indicated to create or to update the value of the variable whose name is varname. If there is no value term, the current value of the variable is returned. If the value of a non-existent variable is queried, an error is returned. You can query a variable inside of catch to test for the existence of a variable; or use the -enum switch discussed below.

The default behavior when setting a variable is to attempt to set it for the machine. If the current user does not have permission to alter the machine settings the variable is set for the current user. The user must belong to the Administrator security group to be able to alter the machine settings. The machine settings are in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment. The user settings are in the registry under HKEY_CURRENT_USER\Environment. The registry location can be explicitly targeted by specifying the optional switch -machine_env or the optional switch -user_env.

When a variable is set, if the value text contains embedded NT style substitutions like %COMPUTERNAME% or %SystemRoot%, the variable is given the data type REG_EXPAND_SZ. This data type indicates that Windows NT should substitute for the embedded variable at the time the value of the variable is referenced. If the value text does not contain any NT style substitutions (names delimited with %'s), then it is given the data type REG_SZ. For example:

regset DISPLAY %COMPUTERNAME%:0.0
creates the environmental variable DISPLAY which has the correct value even if the computer is renamed.

Actually, only a simple, naive check is made for the presence of %token% embedded substitutions. If the text has two or more %'s in it separated by 1 or more characters, it is assumed to be REG_EXPAND_SZ. You need to override the default data type if you wish to have a REG_SZ string that has more than one % character in it, or wish to have a REG_EXPAND_SZ string with less than two % characters in it. Use the switches -REG_SZ or -REG_EXPAND_SZ to explicitly specify the assigned data type.

The switch -enum is used to enumerate existing environment variables. A list of Tcl statements is returned that could be used to create or recreate the existing values. You may use the -enum switch with the switches -machine_env or -user_env to limit the enumerated list to just the desired environment; the default is to obtain both. When the -enum switch is given, the user does not specify the varname or value arguments.

The switch -delete is used to remove a variable. Unless the -machine_env or -user_env switches are used to limit the scope, the variable is deleted from both the machine and the user environment if the user has the privileges to do so. The command returns a count of the entries deleted. The returned count may may be zero; it is not an error to delete a non-existent variable. However, an error is returned if -machine_env or -user_env is explicitly specified, and the user does not have security credentials to carry out the deletion.

By default, as you make changes to the registry, other programs do not know that changes have occured. The flag -announce is used to broadcast a message that the environment has changed. When this flag is used, the Program Manager and possibly other applications, update their knowledge of the environment settings. Subsequent processes started by the Program Manager are consequently given the new environment settings. If you are making several changes to the registry, it is much more efficient to use the -announce flag only on the last change, or to use regset -announce as the final command.

Technically, the announce option causes the WM_WININICHANGE message to be sent to all toplevel windows with the LPARAM sendmessage() parameter being a pointer to the string "Environment".

SEE ALSO

tclvars (variable env)

AUTHOR

Ed Hume, Hume Integration Software This is licensed software, (C)Copyright 1995, all rights reserved.

KEYWORDS

NT registry, environment