WinReg Package

Author: forliny. On GitHub: forliny/TbWinReg

The WinReg contributed package provides a Windows Registry helper class that reads, writes, deletes, and enumerates registry keys and values through the Win32 advapi32 API. The package exposes a single RegCls class wrapping the most common registry operations into a convenient interface. It depends on types and API declarations from the WinDevLib package.

WinReg references the WinDevLib package, but a project does not see the names a package’s own references declare. A project that names WinDevLib’s root keys (HKEY_CURRENT_USER), value types (REGTYPES) or BOOL, as the examples here do, references WinDevLib as well. One that declares the Dictionary that EnumValues returns references the Microsoft Scripting Runtime.

Note

Version 0.0.0.0 does not compile in twinBASIC BETA 1005, so a project that references it does not build. RegCls passes VarPtr(0&) to two ByRef structure parameters of WinDevLib’s declarations: lpSecurityAttributes of RegCreateKeyEx and lpftLastWriteTime of RegEnumKeyEx. A pointer passed for a structure has to be passed ByVal (error TB5001).

Classes

  • RegCls – a Windows Registry helper class that reads, writes, deletes, and enumerates registry keys and values through the Win32 advapi32 API
    • ConvertValueToString – converts a registry value (from an open key handle or a byte array) to its String representation
    • CreateKey – creates a registry key, including any intermediate keys in the path that do not already exist
    • DeleteKey – deletes a registry key that has no subkeys
    • DeleteKeyEx – recursively deletes a registry key and all of its subkeys and values
    • DeleteValue – deletes a named value from a registry key
    • EnumValues – returns a Dictionary containing the names and string representations of all values under a registry key
    • GetRegistryValueType – returns the data type of a named registry value without reading its data
    • KeyExists – returns True if the specified registry key exists, False otherwise
    • ReadDWORD – reads a REG_DWORD value from the Windows registry and returns it as a Long
    • ReadString – reads a REG_SZ string value from the Windows registry and returns it as a String
    • ValueExists – returns True if a named value exists under the specified registry key
    • WriteDWORD – writes a 32-bit integer value (REG_DWORD) to a registry key, creating the key if it does not already exist
    • WriteString – writes a string value to a registry key, creating the key if it does not exist