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

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

Parameters

hDefKey [in, optional]

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

Be aware that HKEY_DYN_DATA is a valid tree only for computers running on the Windows 95 or Windows 98 operating system.

The following trees are defined in Winreg.h.

NameValue

HKEY_CLASSES_ROOT

2147483648 (0x80000000)

HKEY_CURRENT_USER

2147483649 (0x80000001)

HKEY_LOCAL_MACHINE

2147483650 (0x80000002)

HKEY_USERS

2147483651 (0x80000003)

HKEY_CURRENT_CONFIG

2147483653 (0x80000005)

HKEY_DYN_DATA

2147483654 (0x80000006)

 

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.

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)

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.

Examples

For script code examples, see WMI Tasks: Registry and the TechNet ScriptCenter Script Repository. Other examples are in books and articles listed in Further Information.

For C++ code examples, see WMI C++ Application Examples.

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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
MOFRegevent.mof
DLLStdprov.dll
Namespace\root\default

See Also

StdRegProv
Modifying the System Registry
WMI Tasks: Registry

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags :


Community Content

Thomas Lee
Doesn't enumerate a lone default value
There is a long-standing bug in this method (Windows 2000 through Vista). If there is no value in the key other than the default value, EnumValues does not return the default value. If at least one other value is defined in the key, the default value will be returned in sValues.

JayTee_72
Need to check IsNull when using EnumValues

This is not quite a bug and is NOT the same problem as RegRead. This method returns a null value for the array when the default value is the only one present. The script does need to have an IsNull check, though, as should be done before any access to a VBScript variant.

Would someone please provide a good working example that includes the logic to return the Default value when it is the only one present? Thanks.

Tags : contentbug

André Laszlo
QWORD value type is missing from this page
There is also a "REG_QWORD", but it's not declared in the winnt.h header file. A QWORD value has the type 11.

xhoward
C++ example
Is there a C++ example for this method? What C++ header file should be included? Any C++ library?
Tags :

Page view tracker