Microsoft KB Archive/307308

= RegQueryInfoKey Function May Return Zero for ControlSetnnn Subkey Parameters =

PSS ID Number: 307308

Article Last Modified on 12/5/2003

-

The information in this article applies to:


 * Microsoft Windows 2000 Server SP1
 * Microsoft Windows 2000 Server SP2
 * Microsoft Windows 2000 Advanced Server SP1
 * Microsoft Windows 2000 Advanced Server SP2
 * Microsoft Windows 2000 Professional SP1
 * Microsoft Windows 2000 Professional SP2

-



This article was previously published under Q307308



SYMPTOMS
The Win32 application programming interface (API) RegQueryInfoKey function that retrieves information about a specific registry key, may incorrectly return zero (0) in the DWORD variables that are pointed to by the lpcSubKeys (number of registry subkeys) and lpcMaxSubKeyLen (longest registry subkey name) parameters.

This problem typically occurs in the current copy of the last known good control set.



CAUSE
This problem can occur when your computer saves a copy of the last known good configuration (typically, ControlSet001 is copied to ControlSet002) after a successful boot because the count of some items and the size of the largest registry subkey are not copied correctly.



RESOLUTION
To resolve this problem, obtain the latest service pack for Windows 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

260910 How to Obtain the Latest Windows 2000 Service Pack



WORKAROUND
To work around this problem, you can increment the dwIndex parameter during iterative calls to RegEnumKeyEx until it returns ERROR_NO_MORE_ITEMS to find the total number of subkeys in a registry key. For an example about how to do this, view the following sample code:
 * 1) include 


 * 1) define ALLOC_SIZE(n)  (SIZE_T)((n)*sizeof(TCHAR))

LONG MyRegQueryInfoKey(        HKEY      hKey,                   // handle to key         LPTSTR    lpClass,                // class buffer         LPDWORD   lpcClass,               // size of class buffer         LPDWORD   lpReserved,             // reserved         LPDWORD   lpcSubKeys,             // number of subkeys         LPDWORD   lpcMaxSubKeyLen,        // longest subkey name         LPDWORD   lpcMaxClassLen,         // longest class string         LPDWORD   lpcValues,              // number of value entries         LPDWORD   lpcMaxValueNameLen,     // longest value name         LPDWORD   lpcMaxValueLen,         // longest value data         LPDWORD   lpcbSecurityDescriptor, // descriptor length         PFILETIME lpftLastWriteTime       // last write time         ) {  LONG l;

l = RegQueryInfoKey( hKey, lpClass, lpcClass, lpReserved, lpcSubKeys,                       lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues,                        lpcMaxValueNameLen, lpcMaxValueLen,                        lpcbSecurityDescriptor, lpftLastWriteTime );

if ( ERROR_SUCCESS == l &&       ( (lpcSubKeys && 0 == *lpcSubKeys) || (lpcMaxSubKeyLen && 0 == *lpcMaxSubKeyLen) ) ) {     DWORD    cSubKeys = 0; DWORD   cMaxSubKeyLen = 0; DWORD   cSubKeyLen = 0; LPTSTR  lpName = (LPTSTR)LocalAlloc( LPTR, ALLOC_SIZE(MAX_PATH+1) ); FILETIME fTime;

while ( 1 ) {        l = RegEnumKeyEx( hKey, cSubKeys, lpName, &cSubKeyLen,                           NULL, NULL, NULL, &fTime ); if ( cSubKeyLen > cMaxSubKeyLen ) cMaxSubKeyLen = cSubKeyLen; switch ( l ) {        case ERROR_SUCCESS: case ERROR_MORE_DATA: cSubKeys++; break;

case ERROR_NO_MORE_ITEMS: if ( lpcSubKeys ) *lpcSubKeys = cSubKeys; if ( lpcMaxSubKeyLen ) *lpcMaxSubKeyLen = cMaxSubKeyLen; l = ERROR_SUCCESS;

default: LocalFree( (HLOCAL)lpName ); return l;        } }  }   return l; } Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

http://www.microsoft.com/partner/referral/

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Windows 2000 Service Pack 3.



MORE INFORMATION
You can locate the ControlSetnnn control set keys in the following registry keys:

HKEY_LOCAL_MACHINE\System\ControlSet001

-and-

HKEY_LOCAL_MACHINE\System\ControlSet002

Note that ControlSet003 quits only if you use the Last Known Good boot option.

You can locate the CurrentControlSet key in the following registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet

Note that CurrentControlSet is a symbolic link to one of the ControlSetnnn keys, where nnn is in the following registry key value:

HKEY_LOCAL_MACHINE\System\Select\LastKnownGood

For additional information about control sets, click the article number below to view the article in the Microsoft Knowledge Base:

100010 What are Control Sets? What is CurrentControlSet?

For additional information about how to use LastKnownGood, click the article number below to view the article in the Microsoft Knowledge Base:

142033 Restoring Previous ControlSet After Using LastKnownGood

Additional query words: kbBaseOS RegQueryInfoKey LastKnownGood lkg

Keywords: kbbug kbcode kbfix kbOSWin2000fix kbRegistry kbWin2000sp3fix KB307308

Technology: kbwin2000AdvServ kbwin2000AdvServSearch kbWin2000AdvServSP1 kbWin2000AdvServSP2 kbwin2000Pro kbwin2000ProSearch kbWin2000ProSP1 kbWin2000ProSP2 kbwin2000Search kbwin2000Serv kbwin2000ServSearch kbwin2000ServSP1 kbwin2000ServSP2 kbWinAdvServSearch

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.