9 Windows Registry
(require file/resource) |
| ||||||||||||||||||||
→ (or/c #f string? bytes? exact-integer? #t) | ||||||||||||||||||||
| ||||||||||||||||||||
entry : string? | ||||||||||||||||||||
| ||||||||||||||||||||
file : #f = #f | ||||||||||||||||||||
type : (or/c 'string 'bytes 'integer) = derived-from-value-box |
The resource value is keyed on the combination of section and entry. The result is #f if no value is found for the specified section and entry. If value-box is a box, then the result is #t if a value is found, and the box is filled with the value; when value-box is #f, the result is the found value.
The type argument determines how a value in the registry is converted to a Racket value. If value-box is a box, then the default type is derived from the initial box content, otherwise the default type is 'string.
Registry values of any format can be extracted. Values using the registry format REG_SZ are treated as strings, and values with the format REG_DWORD are treated as 32-bit signed integers. All other formats are treated as raw bytes. Data from the registry is converted to the requested type type:
A REG_SZ registry value is converted to an integer using string->number (using 0 if the result is not an exact integer), and it is converted to bytes using string->bytes/utf-8.
A REG_DWORD registry value is converted to a string or byte string via number->string and (for byte strings) string->bytes/utf-8.
Any other kind of registry value is converted to a string or integer using bytes->string/utf-8 and (for integers) string->number.
The file argument is included for backward compatibility and must be #f.
To get the “default” value for an entry, use a trailing backslash. For example, the following expression gets a command line for starting a browser:
(get-resource "HKEY_CLASSES_ROOT" |
"htmlfile\\shell\\open\\command\\") |
| ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
entry : string? | ||||||||||||||||||||||||||||||||||||||||||
value : (or/c string? bytes? exact-integer?) | ||||||||||||||||||||||||||||||||||||||||||
file : #f = #f | ||||||||||||||||||||||||||||||||||||||||||
type : (or/c 'string 'bytes 'integer) = 'string | ||||||||||||||||||||||||||||||||||||||||||
create-key? : any/c = #f |
The resource value is keyed on the combination of section and entry. If create-key? is false, the resource entry must already exist, otherwise the write fails. The result is #f if the write fails or #t if it succeeds.
The type argument determines the format of the value in the registry: 'string writes using the REG_SZ format, 'bytes writes using the REG_BINARY format, and 'dword writes using the REG_DWORD format. Any kind of value can be converted for any kind of type using the inverse of the conversions for get-resource.
The file argument must be #f. A path is allowed for backward compatibility of arguments, but providing a path causes an exn:fail:unsupported exception to be raised.