1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . R E G I S T R Y --
9 -- Copyright (C) 2001-2003 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 ------------------------------------------------------------------------------
33 -- The registry is a Windows database to store key/value pair. It is used
34 -- to keep Windows operation system and applications configuration options.
35 -- The database is a hierarchal set of key and for each key a value can
36 -- be associated. This package provides high level routines to deal with
37 -- the Windows registry. For full registry API, but at a lower level of
38 -- abstraction, refer to the Win32.Winreg package provided with the
39 -- Win32Ada binding. For example this binding handle only key values of
40 -- type Standard.String.
42 -- This package is specific to the NT version of GNAT, and is not available
43 -- on any other platforms.
45 package GNAT
.Registry
is
48 -- HKEY is a handle to a registry key, including standard registry keys:
49 -- HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER,
50 -- HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA.
52 HKEY_CLASSES_ROOT
: constant HKEY
;
53 HKEY_CURRENT_USER
: constant HKEY
;
54 HKEY_CURRENT_CONFIG
: constant HKEY
;
55 HKEY_LOCAL_MACHINE
: constant HKEY
;
56 HKEY_USERS
: constant HKEY
;
57 HKEY_PERFORMANCE_DATA
: constant HKEY
;
59 type Key_Mode
is (Read_Only
, Read_Write
);
60 -- Access mode for the registry key.
62 Registry_Error
: exception;
63 -- Registry_Error is raises by all routines below if a problem occurs
64 -- (key cannot be opened, key cannot be found etc).
69 Mode
: Key_Mode
:= Read_Write
)
71 -- Open or create a key (named Sub_Key) in the Windows registry database.
72 -- The key will be created under key From_Key. It returns the key handle.
73 -- From_Key must be a valid handle to an already opened key or one of
74 -- the standard keys identified by HKEY declarations above.
79 Mode
: Key_Mode
:= Read_Only
)
81 -- Return a registry key handle for key named Sub_Key opened under key
82 -- From_Key. It is possible to open a key at any level in the registry
83 -- tree in a single call to Open_Key.
85 procedure Close_Key
(Key
: HKEY
);
86 -- Close registry key handle. All resources used by Key are released.
88 function Key_Exists
(From_Key
: HKEY
; Sub_Key
: String) return Boolean;
89 -- Returns True if Sub_Key is defined under From_Key in the registry.
94 Expand
: Boolean := False)
96 -- Returns the registry key's value associated with Sub_Key in From_Key
97 -- registry key. If Expand is set to True and the Sub_Key is a
98 -- REG_EXPAND_SZ the returned value will have the %name% variables
99 -- replaced by the corresponding environment variable value.
101 procedure Set_Value
(From_Key
: HKEY
; Sub_Key
: String; Value
: String);
102 -- Add the pair (Sub_Key, Value) into From_Key registry key.
104 procedure Delete_Key
(From_Key
: HKEY
; Sub_Key
: String);
105 -- Remove Sub_Key from the registry key From_Key.
107 procedure Delete_Value
(From_Key
: HKEY
; Sub_Key
: String);
108 -- Remove the named value Sub_Key from the registry key From_Key.
111 with procedure Action
115 Quit
: in out Boolean);
116 procedure For_Every_Key_Value
(From_Key
: HKEY
; Expand
: Boolean := False);
117 -- Iterates over all the pairs (Sub_Key, Value) registered under
118 -- From_Key. Index will be set to 1 for the first key and will be
119 -- incremented by one in each iteration. Quit can be set to True to
120 -- stop iteration; its initial value is False.
122 -- Key value that are not of type string (i.e. not REG_SZ / REG_EXPAND_SZ)
123 -- are skipped. In this case, the iterator behaves exactly as if the key
124 -- were not present. Note that you must use the Win32.Winreg API to deal
125 -- with this case. Furthermore, if Expand is set to True and the Sub_Key
126 -- is a REG_EXPAND_SZ the returned value will have the %name% variables
127 -- replaced by the corresponding environment variable value.
131 type HKEY
is mod 2 ** Integer'Size;
133 HKEY_CLASSES_ROOT
: constant HKEY
:= 16#
80000000#
;
134 HKEY_CURRENT_USER
: constant HKEY
:= 16#
80000001#
;
135 HKEY_LOCAL_MACHINE
: constant HKEY
:= 16#
80000002#
;
136 HKEY_USERS
: constant HKEY
:= 16#
80000003#
;
137 HKEY_PERFORMANCE_DATA
: constant HKEY
:= 16#
80000004#
;
138 HKEY_CURRENT_CONFIG
: constant HKEY
:= 16#
80000005#
;