Purpose: collect tips, techniques, and suggestions for making careful use of the Windows registry extension http://www.purl.org/tcl/home/man/tcl8.4/TclCmd/registry.htm ---- [Windows Registry Browser] is an example of use of the registry extension. Other examples include: * tests/registry.test from the standard source distribution (is there a URL for individual sources?); * "[Printing under Windows]"; * [Melissa Schrumpf]'s enablement of cmd.exe autocompletion [http://www.geocities.com/m_schrumpf/tcl/index.html#autocomplete], [Windows] search path management [http://www.geocities.com/m_schrumpf/tcl/index.html#installbin], and [COM] introspection [http://www.geocities.com/m_schrumpf/tcl/index.html#comtree] or tree browsing ---- There's more at [Microsoft Windows and Tk]. Among the most interesting: * [Register file types under Windows] shows how to choose a file extension and assign it to your application. * [Windows: getting desktop properties] shows how to get the attributes of the system desktop so that your app's look and feel can be configured to match. * [Windows: setting environment Path] shows how to get and set registry keys for the environment path. ---- [Chin Huang] offers an example: "this Tcl script lists the programmatic identifier ([ProgID]) of all [COM] classes that have a ProgID. package require registry set classesRootKey "HKEY_CLASSES_ROOT\\CLSID" foreach clsid [registry keys $classesRootKey] { set clsidKey "$classesRootKey\\$clsid" set progIdSubKey [registry keys $clsidKey "VersionIndependentProgID"] if {[llength $progIdSubKey] > 0} { set progId [registry get "$clsidKey\\$progIdSubKey" ""] puts $progId } } ". Typical values seen include "Shell.Explorer", "Adobe.SVGCtl", "InternetExplorer.Application", "PowerPoint.Show", "FrameMaker.Api", and so on. An apparent approximation is "Do [[registry keys HKEY_CLASSES_ROOT]. Discard the ones with leading periods. For all that remain, do [[registry get HKEY_CLASSES_ROOT\\$key\\CLSID - if you find it, you know a progID and CLSID ..." ---- [Tom Wilkason] wrote in [the comp.lang.tcl newsgroup]: Below is what I do to set system env variables on Win2K (need admin priv for system variables). Note, you generally have to logout for them to take effect. ;## ;# Set a user Env variable, may have to logout first ;# proc setUserEnv {key value} { package require registry global env if {[catch { registry set "HKEY_CURRENT_USER\\Environment" $key $value } result]} { puts stderr "$result" } set env($key) $value } ;## ;# Set a system wide Env variable, if fails set the user env variable instead ;# proc setSysEnv {key value} { package require registry global env if {[catch { registry set "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment" $key $value registry set "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet002\\Control\\Session Manager\\Environment" $key $value registry set "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" $key $value } result]} { registry set "HKEY_CURRENT_USER\\Environment" $key puts stderr "$result" } else { catch {registry delete "HKEY_CURRENT_USER\\Environment" $key} } set env($key) $value } [Earl Johnson] A while back I wrote a wrapper around many of the common uses of the registry. You can find it at [ms_shell_setup] ---- Mick O'Donnell [http://www.wagsoft.com/]: The location of the Desktop Folder can be recovered using the following code. As the exact registry key which stores this information seems to vary from OS to OS, and between single and multiple user machines, the code tries various locations until it finds the key: ''[MG] editing slightly to lessen the need for escaping'' proc desktop-location {} { # Load the registry package package require registry # Define likely registry locations set keys [list {HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders}\ {HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProfileList}\ {HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders}] # Try each location till we find a result foreach key $keys { if {![catch {registry get $key Desktop} result]} { return $result } } } [MG] also finds this info in the $env variable, on his XP machine on June 14 2005. file join $env(USERPROFILE) Desktop ;# desktop for this user only file join $env(ALLUSERSPROFILE) Desktop ;# Desktop for all users of this machine Whether that's standard, though, I couldn't say. ---- [RLH]: One good place to look for tips on how to manipulate the registry is in the test scripts that come with the standard Tcl download. ---- [Robert Joy]: I'm wondering if anyone has considered adding the microsoft security functions, ie; the RegGetKeySecurity and RegSetKeySecurity. This would be useful for adding license keys to the registry and not allowing them to be removed without the proper authorization. ---- Back to [Tcl core extension syntax]. ---- [Tcl syntax help] - [Category Command] - [Category Windows]