| Previous | Main | Site Index | Download | Disclaimer | Privacy |
SUPPLEMENTARY NOTE
This supplementary note provides information for functions and structures used in program examples of Module O and Module P. The information compiled for NT 5 (Windows 2000 and above).
IndexStructuresVALENTFILETIMEPDH_COUNTER_PATH_ELEMENTSOSVERSIONINFOOSVERSIONINFOEXFunctionsRegEnumKeyEx()RegQueryInfoKey()RegEnumValue()PdhMakeCounterPath()PdhAddCounter()PdhCollectQueryData()PdhGetRawCounterValue()PdhCloseQuery()PdhOpenQuery()PdhRemoveCounter()PdhOpenQueryH()RegOpenKey()RegCloseKey()RegQueryValueEx()RegCreateKeyEx()RegSetValueEx()RegOpenKeyEx()RegOpenCurrentUser()RegOpenUserClassesRoot()RegQueryMultipleValues()GetVersionEx()RegDeleteKey() |
|
Structures
|
Item |
Description |
|
Structure |
VALENT. |
|
Info |
Contains information about a registry value. The RegQueryMultipleValues() function uses this structure. |
|
Definition |
typedef struct value_ent {
} VALENT, |
|
Members |
ve_valuename Pointer to a null-terminated string. Before calling RegQueryMultipleValues(), set this member to point to the name of a value to retrieve.
ve_valuelen Size of the data pointed to by ve_valueptr, in bytes.
ve_valueptr Pointer to the data for the value entry. This is a pointer to the value's data returned in the lpValueBuf buffer filled in by RegQueryMultipleValues().
ve_type Type of data pointed to by ve_valueptr. |
|
Header file |
<windows.h> |
|
Remark |
Declared as Unicode and ANSI structures. |
|
Table 1. |
|
|
Item |
Description |
|
Structure |
FILETIME. |
|
Info |
A 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). |
|
Definition |
typedef struct _FILETIME {
} FILETIME, |
|
Members |
dwLowDateTime - Low-order part of the file time. dwHighDateTime - High-order part of the file time. |
|
Header file |
<windows.h> |
|
Remark |
See below. |
|
Table 2. |
|
To convert a FILETIME structure into a time that is easy to display to a user, use the FileTimeToSystemTime() function. It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should:
▪ Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
▪ Use normal 64-bit arithmetic on the ULARGE_INTEGER value.
Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, the GetFileTime() function may not return the same file time information set using the SetFileTime() function. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC.
|
Item |
Description |
|
Structure |
PDH_COUNTER_PATH_ELEMENTS. |
|
Info |
Contains the parsed elements of a fully qualified counter path. The main purpose of this structure is to provide formatted text to the calling application for display. |
|
Definition |
typedef struct _PDH_COUNTER_PATH_ELEMENTS {
} PDH_COUNTER_PATH_ELEMENTS, |
|
Members |
szMachineName - Pointer to a null-terminated string that specifies the computer name. szObjectName - Pointer to a null-terminated string that specifies the object name. szInstanceName - Pointer to a null-terminated string that specifies the instance name. szParentInstance - Pointer to a null-terminated string that specifies the parent instance name. dwInstanceIndex - Index of duplicate instance names. szCounterName - Pointer to a null-terminated string that specifies the counter name. |
|
Header file |
<pdh.h> |
|
Remark |
Declared as Unicode and ANSI structures. |
|
Table 3. |
|
|
Item |
Description |
|
Structure |
OSVERSIONINFO. |
|
Info |
Contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and descriptive text about the operating system. This structure is used with the GetVersionEx() function. To obtain additional version information, see the OSVERSIONINFOEX structure. |
|
Definition |
typedef struct _OSVERSIONINFO { } OSVERSIONINFO; |
|
Members |
See below. |
|
Header file |
<windows.h> |
|
Remark |
Declared as Unicode and ANSI structures. Relying on version information is not the best way to test for a feature. Instead, refer to the documentation for the feature of interest. If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for the one operating system. This way, your detection code will continue to work on future versions of Windows. |
|
Table 4. |
|
dwOSVersionInfoSize
Size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFO) before calling the GetVersionEx function.
dwMajorVersion
Major version number of the operating system. This member can be one of the following values.
|
Operating System |
Meaning |
|
Windows 95 |
4 |
|
Windows 98 |
4 |
|
Windows Me |
4 |
|
Windows NT 3.51 |
3 |
|
Windows NT 4.0 |
4 |
|
Windows 2000 |
5 |
|
Windows XP |
5 |
|
Windows Server 2003 family |
5 |
|
Table 5. |
|
dwMinorVersion
Minor version number of the operating system. This member can be one of the following values.
|
Operating System |
Meaning |
|
Windows 95 |
0 |
|
Windows 98 |
10 |
|
Windows Me |
90 |
|
Windows NT 3.51 |
51 |
|
Windows NT 4.0 |
0 |
|
Windows 2000 |
0 |
|
Windows XP |
1 |
|
Windows Server 2003 family |
2 |
|
Table 6. |
|
dwBuildNumber
Build number of the operating system. For Windows Me/98/95: The low-order word contains the build number of the operating system. The high-order word contains the major and minor version numbers.
dwPlatformId
Operating system platform. This member can be one of the following values.
|
Value |
Meaning |
|
VER_PLATFORM_WIN32s |
Win32s on Windows 3.1. |
|
VER_PLATFORM_WIN32_WINDOWS |
Windows 95, Windows 98, or Windows Me. |
|
VER_PLATFORM_WIN32_NT |
Windows NT, Windows 2000, Windows XP, or Windows Server 2003 family. |
|
Table 7. |
|
szCSDVersion
Pointer to a null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty. For Windows Me/98/95: Pointer to a null-terminated string that indicates additional version information. For example, " C" indicates Windows 95 OSR2 and " A" indicates Windows 98 Second Edition.
|
Item |
Description |
|
Structure |
OSVERSIONINFOEX. |
|
Info |
Contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and information about product suites and the latest Service Pack installed on the system. This structure is used with the GetVersionEx() and VerifyVersionInfo() functions. |
|
Definition |
typedef struct _OSVERSIONINFOEX {
} OSVERSIONINFOEX, |
|
Members |
See below. |
|
Header file |
<windows.h> |
|
Remark |
Declared as Unicode and ANSI structures. Relying on version information is not the best way to test for a feature. Instead, refer to the documentation for the feature of interest. If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for the one operating system. This way, your detection code will continue to work on future versions of Windows. Note that you should not solely rely upon the VER_SUITE_SMALLBUSINESS flag to determine whether Small Business Server has been installed on the system, as both this flag and the VER_SUITE_SMALLBUSINESS_RESTRICTED flag are set when this product suite is installed. If you upgrade this installation to Windows Server, Standard Edition, the VER_SUITE_SMALLBUSINESS_RESTRICTED flag will be unset however, the VER_SUITE_SMALLBUSINESS flag will remain set. In this case, this indicates that Small Business Server was once installed on this system. If this installation is further upgraded to Windows Server, Enterprise Edition, the VER_SUITE_SMALLBUSINESS key will remain set. To determine whether a Win32-based application is running on WOW64, call the IsWow64Process() function. |
|
Table 8. |
|
dwOSVersionInfoSize
Size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX) before calling the GetVersionEx() or VerifyVersionInfo() function.
dwMajorVersion
Major version number of the operating system. This member can be one of the following values.
|
Operating System |
Meaning |
|
Windows NT 4.0 |
4 |
|
Windows 2000 |
5 |
|
Windows XP |
5 |
|
Windows Server 2003 family |
5 |
|
Table 9. |
|
dwMinorVersion
Minor version number of the operating system. This member can be one of the following values.
|
Operating System |
Meaning |
|
Windows NT 4.0 |
0 |
|
Windows 2000 |
0 |
|
Windows XP |
1 |
|
Windows Server 2003 family |
2 |
|
Table 10. |
|
dwBuildNumber
Build number of the operating system.
dwPlatformId
Operating system platform. This member can be VER_PLATFORM_WIN32_NT.
szCSDVersion
Pointer to a null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.
wServicePackMajor
Major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the major version number is 3. If no Service Pack has been installed, the value is zero.
wServicePackMinor
Minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the minor version number is 0.
wSuiteMask
Bit flags that identify the product suites available on the system. This member can be a combination of the following values.
|
Value |
Meaning |
|
VER_SUITE_BACKOFFICE |
Microsoft BackOffice components are installed. |
|
VER_SUITE_BLADE |
Windows Server 2003, Web Edition is installed. |
|
VER_SUITE_DATACENTER |
Windows 2000 Datacenter Server or Windows Server 2003, Datacenter Edition is installed. |
|
VER_SUITE_ENTERPRISE |
Windows NT 4.0 Enterprise Edition, Windows 2000 Advanced Server, or Windows Server 2003, Enterprise Edition is installed. Refer to the Remarks section for more information about this bit flag. |
|
VER_SUITE_PERSONAL |
Windows XP Home Edition is installed. |
|
VER_SUITE_SMALLBUSINESS |
Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. |
|
VER_SUITE_SMALLBUSINESS_RESTRICTED |
Microsoft Small Business Server is installed with the restrictive client license in force. |
|
VER_SUITE_TERMINAL |
Terminal Services is installed. |
|
VER_SUITE_SINGLEUSERTS |
Terminal Services is installed, but only one interactive session is supported. |
|
Table 11. |
|
wProductType
Additional information about the system. This member can be one of the following values.
|
Value |
Meaning |
|
VER_NT_WORKSTATION |
The system is running Windows NT 4.0 Workstation, Windows 2000 Professional, Windows XP Home Edition, or Windows XP Professional. |
|
VER_NT_DOMAIN_CONTROLLER |
The system is a domain controller. |
|
VER_NT_SERVER |
The system is a server. |
|
Table 12. |
|
wReserved
Reserved for future use.
Functions
|
Item |
Description |
|
Function |
RegEnumKeyEx(). |
|
Use |
Enumerates subkeys of the specified open registry key. The function retrieves information about one subkey each time it is called. |
|
Prototype |
LONG RegEnumKeyEx( HKEY hKey, DWORD dwIndex, LPTSTR lpName, LPDWORD lpcName, LPDWORD lpReserved, LPTSTR lpClass, LPDWORD lpcClass, PFILETIME lpftLastWriteTime); |
|
Parameters |
hKey [in] Handle to an open key. The key must have been opened with the KEY_ENUMERATE_SUB_KEYS access right. This handle is returned by the RegCreateKeyEx() or RegOpenKeyEx() function or it can be one of the following predefined keys:
HKEY_CLASSES_ROOT Windows Me/98/95: This parameter can also be the following value: HKEY_DYN_DATA
dwIndex [in] Index of the subkey to retrieve. This parameter should be zero for the first call to the RegEnumKeyEx() function and then incremented for subsequent calls. Because subkeys are not ordered, any new subkey will have an arbitrary index. This means that the function may return subkeys in any order.
lpName [out] Pointer to a buffer that receives the name of the subkey, including the terminating null character. The function copies only the name of the subkey, not the full key hierarchy, to the buffer.
lpcName [in, out] Pointer to a variable that specifies the size of the buffer specified by the lpName parameter, in TCHARs. This size should include the terminating null character. When the function returns, the variable pointed to by lpcName contains the number of characters stored in the buffer. The count returned does not include the terminating null character.
lpReserved Reserved; must be NULL.
lpClass [in, out] Pointer to a buffer that receives the null-terminated class string of the enumerated subkey. This parameter can be NULL.
lpcClass [in, out] Pointer to a variable that specifies the size of the buffer specified by the lpClass parameter, in TCHARs. The size should include the terminating null character. When the function returns, lpcClass contains the number of characters stored in the buffer. The count returned does not include the terminating null character. This parameter can be NULL only if lpClass is NULL.
lpftLastWriteTime [out] Pointer to a variable that receives the time at which the enumerated subkey was last written. |
|
Return value |
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a system error code. If there are no more subkeys available, the function returns ERROR_NO_MORE_ITEMS. Windows Server 2003, Windows NT/2000/XP: If the lpName buffer is too small to receive the name of the key, the function returns ERROR_MORE_DATA. |
|
Include file |
<windows.h> |
|
Remark |
Implemented as Unicode and ANSI versions. To enumerate subkeys, an application should initially call the RegEnumKeyEx() function with the dwIndex parameter set to zero. The application should then increment the dwIndex parameter and call RegEnumKeyEx() until there are no more subkeys (meaning the function returns ERROR_NO_MORE_ITEMS). The application can also set dwIndex to the index of the last subkey on the first call to the function and decrement the index until the subkey with the index 0 is enumerated. To retrieve the index of the last subkey, use the RegQueryInfoKey() function. While an application is using the RegEnumKeyEx() function, it should not make calls to any registration functions that might change the key being enumerated. |
|
Table 13. |
|
|
Item |
Description |
|
Function |
RegQueryInfoKey(). |
|
Use |
Retrieves information about the specified registry key. |
|
Prototype |
LONG RegQueryInfoKey( HKEY hKey, LPTSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime); |
|
Parameters |
hKey [in] Handle to an open key. The key must have been opened with the KEY_QUERY_VALUE access right. This handle is returned by the RegCreateKeyEx() or RegOpenKeyEx() function or it can be one of the following predefined keys:
Windows Me/98/95: This parameter can also be the following key: HKEY_DYN_DATA
lpClass [out] Pointer to a buffer that receives the null-terminated class string of the key. This parameter may be ignored. This parameter can be NULL.
lpcClass [in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpClass parameter, in TCHARs. This size should include the terminating null character. When the function returns, this variable contains the size of the class string stored in the buffer. The count returned does not include the terminating null character. If the buffer is not big enough, the function returns ERROR_MORE_DATA, and the variable contains the size of the string, in characters, without counting the null character. If lpClass is NULL, lpcClass can be NULL. Windows NT/2000/XP: If the lpClass parameter is a valid address, but the lpcClass parameter is not (for example, it is NULL), the function returns ERROR_INVALID_PARAMETER. Windows Me/98/95: If the lpClass parameter is a valid address, but the lpcClass parameter is not (for example, it is NULL), the function returns ERROR_SUCCESS instead of ERROR_INVALID_PARAMETER. To ensure compatibility with other platforms, verify that lpcClass is valid before calling the function.
lpReserved Reserved; must be NULL.
lpcSubKeys [out] Pointer to a variable that receives the number of subkeys contained by the specified key. This parameter can be NULL.
lpcMaxSubKeyLen [out] Pointer to a variable that receives the size of the key's subkey with the longest name, in TCHARs. This parameter can be NULL. Windows NT/2000/XP: The size does not include the terminating null character. Windows Me/98/95: The size includes the terminating null character.
lpcMaxClassLen [out] Pointer to a variable that receives the size of the longest string specifying a subkey class, in TCHARs. The count returned does not include the terminating null character. This parameter can be NULL.
lpcValues [out] Pointer to a variable that receives the number of values associated with the key. This parameter can be NULL.
lpcMaxValueNameLen [out] Pointer to a variable that receives the size of the key's longest value name, in TCHARs. The size does not include the terminating null character. This parameter can be NULL.
lpcMaxValueLen [out] Pointer to a variable that receives the size of the longest data component among the key's values, in bytes. This parameter can be NULL.
lpcbSecurityDescriptor [out] Pointer to a variable that receives the size of the key's security descriptor, in bytes. This parameter can be NULL.
lpftLastWriteTime [out] Pointer to a FILETIME structure that receives the last write time. This parameter can be NULL. Windows NT/2000/XP: The function sets the members of the FILETIME structure to indicate the last time that the key or any of its value entries was modified. Windows Me/98/95: The function sets the members of the FILETIME structure to zero. This is because the system does not keep track of registry key last write time information. |
|
Return value |
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in winerror.h. You can use the FormatMessage() function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. |
|
Include file |
<windows.h> |
|
Remark |
Implemented as Unicode and ANSI versions. |
|
Table 14. |
|
|
Item |
Description |
|
Function |
RegEnumValue(). |
|
Use |
Enumerates the values for the specified open registry key. The function copies one indexed value name and data block for the key each time it is called. |
|
Prototype |
LONG RegEnumValue( HKEY hKey, DWORD dwIndex, LPTSTR lpValueName, LPDWORD lpcValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); |
|
Parameters |
hKey [in] Handle to an open key. The key must have been opened with the KEY_QUERY_VALUE access right. This handle is returned by the RegCreateKeyEx() or RegOpenKeyEx() function or it can be one of the following predefined keys:
HKEY_CLASSES_ROOT Windows Me/98/95: This parameter can also be the following value: HKEY_DYN_DATA
dwIndex [in] Index of the value to be retrieved. This parameter should be zero for the first call to the RegEnumValue() function and then be incremented for subsequent calls. Because values are not ordered, any new value will have an arbitrary index. This means that the function may return values in any order.
lpValueName [out] Pointer to a buffer that receives the name of the value, including the terminating null character.
lpcValueName [in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpValueName parameter, in TCHARs. This size should include the terminating null character. When the function returns, the variable pointed to by lpcValueName contains the number of characters stored in the buffer. The count returned does not include the terminating null character.
lpReserved Reserved; must be NULL.
lpType [out] Pointer to a variable that receives a code indicating the type of data stored in the specified value. The lpType parameter can be NULL if the type code is not required.
lpData [out] Pointer to a buffer that receives the data for the value entry. This parameter can be NULL if the data is not required. If lpData is NULL and lpcbData is non-NULL, the function stores the size of the data, in bytes, in the variable pointed to by lpcbData. This enables an application to determine the best way to allocate a buffer for the data.
lpcbData [in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, the variable pointed to by the lpcbData parameter contains the number of bytes stored in the buffer. This parameter can be NULL only if lpData is NULL. If the buffer specified by lpData is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of lpData are undefined. |
|
Return value |
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in winerror.h. You can use the FormatMessage() function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. |
|
Include file |
<windows.h> |
|
Remark |
Implemented as Unicode and ANSI versions. To enumerate values, an application should initially call the RegEnumValue() function with the dwIndex parameter set to zero. The application should then increment dwIndex and calls the RegEnumValue() function until there are no more values (until the function returns ERROR_NO_MORE_ITEMS). The application can also set dwIndex to the index of the last value on the first call to the function and decrement the index until the value with index 0 is enumerated. To retrieve the index of the last value, use the RegQueryInfoKey() function. While using RegEnumValue(), an application should not call any registry functions that might change the key being queried. To determine the maximum size of the name and data buffers, use the RegQueryInfoKey() function. |
|
Table 15. |
|
|
Item |
Description |
|
Function |
PdhMakeCounterPath(). |
|
Use |
Creates a full counter path using the members specified in the structure passed in the parameter list. |
|
Prototype |
PDH_STATUS PdhMakeCounterPath( PDH_COUNTER_PATH_ELEMENTS* pCounterPathElements, LPTSTR szFullPathBuffer, LPDWORD pcchBufferSize, DWORD dwFlags); |
|
Parameters |
See below. |
|
Return value |
See below. |
|
Include file |
<pdh.h> |
|
Remark |
Implemented as Unicode and ANSI versions. The maximum length of a counter path is PDH_MAX_COUNTER_PATH, or 2,048 characters. PDH_MAX_COUNTER_PATH is defined in pdh.h. |
|
Table 16. |
|
pCounterPathElements
[in] Pointer to a PDH_COUNTER_PATH_ELEMENTS structure that contains the individual members those are to make up the path. The following table indicates which members are required and which are optional.
|
Member |
Meaning |
|
szMachineName |
optional |
|
szObjectName |
required |
|
szInstanceName |
optional |
|
szParentInstance |
optional |
|
dwInstanceIndex |
optional ((DWORD)–1 if no index) |
|
szCounterName |
required |
|
Table 17. |
|
If a required member is not present, then no path string will be constructed. If the szMachineName member is NULL, then no computer name will be included in the path (a generic path will be created). If the instance name argument is NULL, then no instance reference will be inserted into the path string and the szParentInstance and the dwInstanceIndex members will be ignored.
szFullPathBuffer
[out] Pointer to a buffer that receives a null-terminated string that specifies the full path.
pcchBufferSize
[in, out] Pointer to a variable that specifies the size of th