GetRegVal, GetRegValName, GetRegValType, GetRegValNameCount Functions

Purpose

These functions enumerates the values for the specified open registry key.

Syntax

$ = GetRegVal(hkey$, idx% [, Int | Bin | Str])

$ = GetRegValName(hkey$, idx%)

% = GetRegValType(hkey$, idx%)

% = GetRegValNameCount(hkey$)

Description

The GetRegVal- functions are used to enumerate the values for the specified open registry key.

The first parameter hkey$ of all functions specifies a key handle obtained with the GFA-BASIC 32 function OpenRegKey.

The idx% parameter specifies the index of the value to retrieve. This parameter should be one (1) for the first call to any of the GetRegVal functions and then be incremented for subsequent calls, until GetRegValNameCount is reached.

GetRegValName obtains the name of the value with index idx%. GetRegValType obtains the type code for the value entry with index idx%. GetRegVal obtains the data for the value entry with index idx%.

Example

DisplayCurrWinVerReg

 

Sub DisplayCurrWinVerReg

Local x$, i%, j%, hkey$

Local key$ = "\\HKEY_LOCAL_MACHINE\Software" _

"\Microsoft\Windows\CurrentVersion"

If IsWinNT     // GetVersion() > 0

key$ = "\\HKEY_LOCAL_MACHINE\Software" _

"\Microsoft\Windows NT\CurrentVersion"

End If

hkey$ = OpenRegKey(key$)

For i% = 1 To GetRegValCount(hkey$)

Print i; Tab(5);

Print GetRegValName(hkey$, i); Tab(30);

Switch GetRegValType(hkey$, i)

Case REG_SZ

Print "Str"; Tab(36);

Write GetRegVal(hkey$, i)

Case REG_DWORD

Print "Int"; Tab(36);

Write GetRegVal(hkey$, i, Int)

Case REG_BINARY

x$ = GetRegVal(hkey$, i, Bin)

Print "Bin"; Tab(36);

For j = 1 To Min(Len(x$), 32)

Print Hex(Asc(x$, j), 2); " ";

Next

Print

Default

Print "Type="; GetRegValType(hkey$, i); Tab(36); _

GetRegVal(hkey$, i)

EndSwitch

Next

CloseRegKey hkey$

EndSub

Remarks

The GetRegVal, GetRegValName, GetRegValType conform to the API function RegEnumValue(). Because this API function is called separately for each function, a little overhead is created, however this is only minimal.

GetRegValNameCount(hkey$) conforms to the API function RegQueryInfoKey(,,,lpcSubKeys,..), which retrieves information about a specified registry key.

See Also

vbSaveSetting, vbDeleteSetting, vbGetSettingType, vbGetSetting, GetSetting, GetSettingType, SaveSetting, DeleteSetting, CreateRegKey, OpenRegKey, CloseRegKey, GetRegVal, GetRegValName, GetRegValType, GetRegValNameCount, GetRegSubKey, GetRegSubKeyCount

{Created by Sjouke Hamstra; Last updated: 07/10/2014 by James Gaite}