FB_RegQueryValue 1:

The system registry is a hierarchically structured tree. A node in the tree is referred to as a key. Each key can may contain subkeys and data values. The function block "FB_RegQueryValue" can be used to read individual system registry values from the branch with the predefined handle HKEY_LOCAL_MACHINE. If successful cbData data bytes are copied into the buffer with the address pData. The function block can be used to read any value types (e.g. REG_DWORD, REG_SZ) or binary data with unlimited byte length (REG_BINARY).


The strings sSubKey and sValueName may not be empty!

FB_RegQueryValue 2:

HKEY_LOCAL_MACHINE\SOFTWARE\ for 64 bit operating systems

In a 64 bit Windows operating system all registry entries of and for 32 bit applications are not stored under HKEY_LOCAL_MACHINE\SOFTWARE\ but under HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\.
The function blocks FB_RegQueryValue and FB_RegSetValue work automatically below the WOW6432Node folder like any 32 bit application when a registry entry below the SOFTWARE folder is selected. The redirection is performed automatically by the operating system.


    sNetId    : T_AmsNetId; 
    sSubKey   : T_MaxString;
    sValName  : T_MaxString;
    cbData    : UDINT;
    pData     : POINTER TO BYTE;
    bExecute  : BOOL;

sNetId: Here you can enter a string with the network address of the TwinCAT computer whose system registry is to be read (type: T_AmsNetID). If it is to be run on the local computer, an empty string can be entered.

sSubKey: String with the subkey name (type: T_MaxString).

sValName: String with the value name (type: T_MaxString).

cbData: The number of value data bytes to be read.

pData: Address of a data buffer/variable into which the value data are to be copied. The address can be determined with the ADR operator. The programmer is responsible for dimensioning the data buffer such that it can accommodate cbData data bytes.

bExecute: the block is activated by a positive edge at this input.

tTimeOut: States the length of the timeout that may not be exceeded by execution of the ADS command.


    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;
    cbRead : UDINT;

bBusy: When the function block is activated this output is set. It remains set until a feedback is received.

bError: In the event of an error during the command transfer, this output is set once the bBusy output has been reset.

nErrId: Supplies the ADS error number or the command-specific error code (table) when the bError output is set.

cbRead: The number of value data bytes successfully read.

Error Codes

Error description


No error


The key with the name sSubKey could not be opened/found.


The key value with the name sValName could not be opened/found.


The values AxisId and LogFilePath are to be read from the system registry.

FB_RegQueryValue 3:

    fbRegQueryValue   : FB_RegQueryValue;
    bRead             : BOOL;
    bBusy             : BOOL;
    bError            : BOOL;
    nErrId            : UDINT;
    cbRead            : UDINT;
    sValData          : STRING;
    nAxisID           : DWORD;

Read REG_DWORD-Value:

FB_RegQueryValue 4:

The value 0x22 of the registry was read in the PLC variable nAxisId .

Read REG_SZ-Value :

FB_RegQueryValue 5:

The string 'c:\MyProject\Log' of the registry was read in the PLC variable sValData.


Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (WES7/Win7/Win10: TC RT x86/x64, WEC6/7: TC RT x86, WEC7: TC CE7 ARMV7, TC/BSD: TC RT x64, TC OS ARMT2)

Tc2_Utilities (System)