Share via


EnumValues method of the StdRegProv class

The EnumValues method enumerates the values of the given subkey. If it has not been changed, the default value of the registry key is always returned. The method returns an empty string ("") if the data is empty. For more information about accessing the registry with WMI, see Obtaining Registry Data.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 EnumValues(
  [in]  uint32 hDefKey = HKEY_LOCAL_MACHINE,
  [in]  string sSubKeyName,
  [out] string sNames[],
  [out] sint32 Types[]
);

Parameters

hDefKey [in]

A registry tree, also known as a hive, that contains the sSubKeyName path. The default value is HKEY_LOCAL_MACHINE.

The following trees are defined in WinReg.h.

HKEY_CLASSES_ROOT (2147483648)

HKEY_CURRENT_USER (2147483649)

HKEY_LOCAL_MACHINE (2147483650)

HKEY_USERS (2147483651)

HKEY_CURRENT_CONFIG (2147483653)

HKEY_DYN_DATA (2147483654)

sSubKeyName [in]

A path that contains the named values to be enumerated.

sNames [out]

An array of named value strings. The elements of this array correspond directly to the elements of the Types parameter. Returns null if only the default value is available.

Types [out]

An array of data value types (integers). You can use these types to determine which of the several Get methods to call. For example, if the data value type is REG_SZ, you call the GetStringValue method to retrieve the named value's data value. The elements of this array correspond directly with the elements of the sNames parameter.

The following data value types are defined in WinNT.h:

  • REG_SZ (1)
  • REG_EXPAND_SZ (2)
  • REG_BINARY (3)
  • REG_DWORD (4)
  • REG_MULTI_SZ (7)
  • REG_QWORD (11)

Returns null if only the default value is available.

Return value

In C++, the method returns a uint32 value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that is defined in WinError.h. In C++, use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. You can also look up return values under the WMI Error Constants.

In scripting or Visual Basic, the method returns an integer value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that you can look up in WbemErrorEnum.

Remarks

Registry subkeys group entries with related information, and it is often useful to display that related information. Unfortunately, this is not necessarily a straightforward procedure; after all, you cannot read a registry value unless you use the appropriate method. But how can you call the appropriate method if you do not know the data type of the value being read?

Fortunately, you can accomplish this task by using the Registry Provider EnumValues method to retrieve an array containing the entry names and an array containing the data type of each entry. After you know the entry name and its data type, you can select the appropriate method to retrieve and display the value of each entry.

This method returns a null value for the array when the default value is the only one present. When writing scripts, be sure to check for the null value (using IsNull); this is a good practice before accessing any VBScript variant.

Examples

The List All Installed Software VBScript sample returns a list of all software installed on a computer, whether or not by Windows Installer, by reading installed applications from the registry.

The Gather Remote Firewall Status And Rules With Powershell sample gathers the firewall status and rules from multiple systems

The following VBScript code example shows how to enumerate the values under:

HKEY_LOCAL_MACHINE\SYSTEM\Current Control Set\Control\Lsa

You can save the script as a file with a .vbs extension and send the output to a file by executing the command line in the folder that contains the script:

cscript Filename.vbs > output.txt

const HKEY_LOCAL_MACHINE = &H80000002
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
   strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Lsa"
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
   arrValueNames, arrValueTypes
For I=0 To UBound(arrValueNames)
    WScript.Echo "Value Name: " & arrValueNames(I) 
    Select Case arrValueTypes(I)
        Case REG_SZ
            WScript.Echo "Data Type: String"
        Case REG_EXPAND_SZ
            WScript.Echo "Data Type: Expanded String"
        Case REG_BINARY
            WScript.Echo "Data Type: Binary"
        Case REG_DWORD
            WScript.Echo "Data Type: DWORD"
        Case REG_MULTI_SZ
            WScript.Echo "Data Type: Multi String"
    End Select 
Next

Requirements

Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\default
MOF
RegEvent.mof
DLL
Stdprov.dll

See also

StdRegProv

Modifying the System Registry

WMI Tasks: Registry