Difference between revisions of "fcl-registry/es"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
 +
 +
{{fcl-registry}}
 +
 +
fcl-registry es una unidad [[FCL]] que permite acceder al registro de Windows.
 +
 +
== Terminología del Registro ==
 +
 +
El registro de Windows contiene un conjunto de entradas o apartados bien diferenciados que denominan "hives", que van creando una estructura en árbol a partir de su raiz "root".
 +
 +
RootKey: es la entrada "hive" que necesaria como comienzo para acceder al registro, como su nombre indica el la "llave raiz" comenzando con la H de Hive.
 +
 +
Ejemplos: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG
 +
 +
Key: es la trayectoria al "directorio" que contiene los datos individuales.  This is a bit counter-intuitive but a holdover con versiones previas del registro.
 +
 +
Name/value (Nombre/Valor): los pares actuales name/value en el directorio de la llave "Key" .Cada llave puede tener un valor por defecto cuyo valor es '' (una cadena vacía).
 +
 +
== Ejemplo ==
 +
 +
Ejemplo que trata de obtener un valor:
 +
 +
<syntaxhighlight>
 +
uses ... registry...
 +
 +
var
 +
  CompileCommand: string='';
 +
  Registry: TRegistry;
 +
begin
 +
  Registry := TRegistry.Create;
 +
  try
 +
    // Navigate to proper "directory":
 +
    Registry.RootKey := HKEY_LOCAL_MACHINE;
 +
    if Registry.OpenKeyReadOnly('\SOFTWARE\Classes\InnoSetupScriptFile\shell\Compile\Command') then
 +
      CompileCommand:=Registry.ReadString(''); //read the value of the default name
 +
  finally
 +
    Registry.Free;
 +
  end;
 +
end;
 +
</syntaxhighlight>
 +
 +
== Accessing 64 bit and 32 bit registry views ==
 +
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.
 +
 +
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
 +
* KEY_WOW64_64KEY: Access a 64-bit key from either a 32-bit or 64-bit application.
 +
* KEY_WOW64_32KEY: Access a 32-bit key from either a 32-bit or 64-bit application.
 +
These keys are defined in the registry unit so you can just use them:
 +
e.g. in the registry object's Access property, like this:
 +
<syntaxhighlight>Registry := TRegistry.Create;
 +
Try
 +
  Registry.Access:=Registry.Access or KEY_WOW64_64KEY;
 +
</syntaxhighlight>
 +
 +
or in the registry.create call, e.g.
 +
<syntaxhighlight>TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);</syntaxhighlight>
 +
 +
== Administrative privileges ==
 +
Depending on what you want to read/write in the registry, you may need administrator rights and  elevation (Windows Vista+). Please see [[IDE_Window:_Project_Options#Use_manifest_file_to_set_execution_level_.28Windows_only.29]]
 +
 +
== See also ==
 +
[[Packages List]]
 +
 +
[[Category:FCL]]
 +
[[Category:FPC]]
 +
[[Category:Standard Units]]
 +
 +
 
{{fcl-registry}}
 
{{fcl-registry}}
  

Revision as of 12:12, 11 March 2016

English (en) español (es) русский (ru)

fcl-registry es una unidad FCL que permite acceder al registro de Windows.

Terminología del Registro

El registro de Windows contiene un conjunto de entradas o apartados bien diferenciados que denominan "hives", que van creando una estructura en árbol a partir de su raiz "root".

RootKey: es la entrada "hive" que necesaria como comienzo para acceder al registro, como su nombre indica el la "llave raiz" comenzando con la H de Hive.

Ejemplos: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG

Key: es la trayectoria al "directorio" que contiene los datos individuales. This is a bit counter-intuitive but a holdover con versiones previas del registro.

Name/value (Nombre/Valor): los pares actuales name/value en el directorio de la llave "Key" .Cada llave puede tener un valor por defecto cuyo valor es (una cadena vacía).

Ejemplo

Ejemplo que trata de obtener un valor:

uses ... registry...

var
  CompileCommand: string='';
  Registry: TRegistry;
begin
  Registry := TRegistry.Create;
  try
    // Navigate to proper "directory":
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKeyReadOnly('\SOFTWARE\Classes\InnoSetupScriptFile\shell\Compile\Command') then
      CompileCommand:=Registry.ReadString(''); //read the value of the default name
  finally
    Registry.Free;
  end;
end;

Accessing 64 bit and 32 bit registry views

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.

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

  • KEY_WOW64_64KEY: Access a 64-bit key from either a 32-bit or 64-bit application.
  • KEY_WOW64_32KEY: Access a 32-bit key from either a 32-bit or 64-bit application.

These keys are defined in the registry unit so you can just use them: e.g. in the registry object's Access property, like this:

Registry := TRegistry.Create;
Try
  Registry.Access:=Registry.Access or KEY_WOW64_64KEY;

or in the registry.create call, e.g.

TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);

Administrative privileges

Depending on what you want to read/write in the registry, you may need administrator rights and elevation (Windows Vista+). Please see IDE_Window:_Project_Options#Use_manifest_file_to_set_execution_level_.28Windows_only.29

See also

Packages List


English (en) español (es) русский (ru)

Registry terms

RootKey (llave raíz): Entradas de registro de almacenaiento (registry hive) donde necesitas comenzar el acceso al registro. EJEMPLOS: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG

Key (llave): la trayectoria al "directorio" que contiene los datos individuales. This is a bit counter-intuitive pero es un vestigio para mantener la compatibilidad con versiones anteriores del registro.

Name/value: the actual name/value pairs in the Key "directory". Each key can have a default value, whose name is (an empty string.

Example

Example that tries to get a value:

uses ... registry...

var
  CompileCommand: string='';
  Registry: TRegistry;
begin
  Registry := TRegistry.Create;
  try
    // Navigate to proper "directory":
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKeyReadOnly('\SOFTWARE\Classes\InnoSetupScriptFile\shell\Compile\Command') then
      CompileCommand:=Registry.ReadString(''); //read the value of the default name
  finally
    Registry.Free;
  end;
end;

See also

Packages List