Sign in Join
Wiki copytemporary

fcl-registry: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: fcl-registry

OldNewLine
1+fcl-registry is an [[FCL]] unit that provides access to the Windows registry. **It is cross-platform**. How? In non-Windows operating systems it creates a `reg.xml` file. For example, under non-Windows operating systems it creates the per user XML file (HKEY_CURRENT_USER) `reg.xml` in the `/home/[user]/.config/application_name/` directory; the global XML file (HKEY_LOCAL_MACHINE) `reg.xml` is created in the `/etc/application_name/` directory which is invariably a read-only location unless you are the root or Admin user.
2+
3+## Registry terms
4+
5+RootKey: registry hive where you want to start accessing the registry. Examples: HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
6+
7+Key: the path to the "directory" that contains individual data. This is a bit counter-intuitive but a holdover from compatibility with earlier versions of the registry.
8+
9+Name/value: the actual name/value pairs in the Key "directory". Each key can have a default value, whose name is *(an empty string)*.
10+
11+## Example
12+
13+Example that tries to get a value:
14+
15+``` pascal
16+uses ... registry...
17+
18+var
19+ CompileCommand: string='';
20+ Registry: TRegistry;
21+begin
22+ Registry := TRegistry.Create;
23+ try
24+ // Navigate to proper "directory":
25+ Registry.RootKey := HKEY_LOCAL_MACHINE;
26+ if Registry.OpenKeyReadOnly('\SOFTWARE\Classes\InnoSetupScriptFile\shell\Compile\Command') then
27+ CompileCommand:=Registry.ReadString(''); //read the value of the default name
28+ finally
29+ Registry.Free; // In non-Windows operating systems this flushes the reg.xml file to disk
30+ end;
31+end;
32+```
33+
34+## Accessing 64 bit and 32 bit registry views
35+
36+If you have 64 bit Windows, the registry is split up into a 64 bit and 32 bit (compatibility) part. By default, if you run a 32 bit process, you see the 32 bit part; if you run a 64 bit application, you see the 64 bit part.
37+
38+You can also access the 32 bit part from 64 bit applications and vice versa. From [MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129%28v=vs.85%29.aspx)
39+
40+- KEY_WOW64_64KEY: Access a 64-bit key from either a 32-bit or 64-bit application.
41+- KEY_WOW64_32KEY: Access a 32-bit key from either a 32-bit or 64-bit application.
42+
43+These keys are defined in the registry unit so you can just use them: eg in the registry object's Access property, like this:
44+
45+``` pascal
46+Registry := TRegistry.Create;
47+Try
48+ Registry.Access:=Registry.Access or KEY_WOW64_64KEY;
49+```
50+
51+or in the registry.create call, eg:
52+
53+``` pascal
54+TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
55+```
56+
57+## Administrative privileges
58+
59+Depending on what you want to read/write in the Windows registry, you may need administrator rights and elevation (Windows Vista+). Please see [[IDE Window: Project Options|Use manifest file to set execution level]]
60+
61+## See also
62+
63+[[Package List|Packages List]]
64+
65+---
66+*From the Free Pascal wiki, page "fcl-registry", as it stood on 2020-05-06 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history