FB_RegSetValue 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_RegSetValue" can be used to write or generate individual key values or new key names and values (subkeys+values) in the branch with the predefined handle HKEY_LOCAL_MACHINE. Any number of value types (e.g. REG_DWORD, REG_SZ) or a maximum of 500 bytes of binary data (REG_BINARY) can be written into the system registry. If a key value does not yet exist, it will automatically be created.


The strings sSubKey and sValueName may not be empty!

FB_RegSetValue 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;
    eValType : E_RegValueType;
    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 written (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).

eValType: The data type format of the registry data to be written, e.g: REG_DWORD or REG_SZ (type: E_RegValueType).

cbData: The number of value data bytes that are to be written. (In the case of string variables this includes the final null).

pD ata: Address of a data buffer/PLC variable containing the value data. The address can be determined with the ADR operator. The programmer is responsible for dimensioning the data buffer such that cbData data bytes can be read from it.

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;
    cbWrite  : 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.

cbWrite: Number of successfully written value data bytes.

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.


In the branch with the predefined handle HKEY_LOCAL_MACHINE a subkey 'SOFTWARE\MyCompany\MyProject' with the key name 'LogFileName' , the type REG_SZ

and the value 'c:\MyProject\Log'' is to be created and set.

    fbRegSetValue   : FB_RegSetValue;
    bBusy               : BOOL;
    bError          : BOOL;
    nErrId          : UDINT;
    cbWrite         : UDINT;
    bWrite          : BOOL;
    sNewValue       : STRING := 'c:\MyProject\Log';

FB_RegSetValue 3:

FB_RegSetValue 4:


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)