BUG: RegQueryInfoKey Returns Length Div 2 for cbMaxSubKeyLen (193465)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98

This article was previously published under Q193465

SYMPTOMS

If a Microsoft Windows 95 or Microsoft Windows 98 computer is connected to a remote Windows 95 or Windows 98 registry and hKey is a handle to an open key in that remote registry, RegQueryInfoKey( hKey, ..., &cbMaxSubKeyLen, ... ) returns only half the actual length of the longest subkey of hKey.

NOTE: Remote registry access is not supported on Windows Millenium Edition.

RESOLUTION

Until this bug is fixed, it is best to allocate a buffer twice as large as cbMaxSubKeyLen.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

Before reproducing this problem, you must make sure that the Remote Administration Services is installed on both Windows 95 or Windows 98 computers. Verify that Microsoft Remote Registry is installed by selecting Network from the Control Panel and scrolling through the list of installed components. For additional information, please see the following article in the Microsoft Knowledge Base:

141460 HOWTO: Install Remote Administration Services

Compile and run the following program from a command prompt on a Windows 95 or Windows 98 computer and pass a parameter identifying another Windows 95 or Windows 98 computer. The reported length of the longest subkey will be half the actual length of that subkey.

Sample Code

   #include <windows.h>
   #include <stdio.h>

   void main( int argc, char* argv[] ) {

       if (argc < 2) {
           printf("Usage: RegConnectRegistry \\\\server");
       } else {

           HKEY hRemoteKey = NULL;
           HKEY hKey = NULL;

           LONG lResult = RegConnectRegistryA( argv[1], HKEY_LOCAL_MACHINE,
               &hRemoteKey);

           if (lResult == ERROR_SUCCESS) {

               printf( "Connected to remote %s registry.\n", argv[1] );

               lResult = RegOpenKeyEx( hRemoteKey, "SOFTWARE", 0,
                   KEY_ALL_ACCESS, &hKey);

               if (lResult == ERROR_SUCCESS) {

                   DWORD cbMaxSubKeyLen;

                   printf( "Key opened.\n" );

                   lResult = RegQueryInfoKey( hKey, NULL, NULL, NULL,
                      NULL, &cbMaxSubKeyLen, NULL, NULL, NULL, NULL, NULL,
                      NULL );

                   if (lResult == ERROR_SUCCESS) {
                       printf( "The max subkey length of %s is %d.\n",
                          "HKEY_LOCAL_MACHINE\\SOFTWARE", cbMaxSubKeyLen );
                   }

                   RegCloseKey( hKey );

               } else {
                   printf( "RegOpenKey() failed.\nError: %d\n", lResult );
               }

               RegCloseKey( hRemoteKey );

           } else {
               printf( "RegConnectRegistry( %s ) failed.\nError: %d\n",
                  argv[1], lResult );
           }
       }
   }
				

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

193463 HOWTO: Troubleshoot Remote Registry Access on Windows 95/98


Modification Type:MajorLast Reviewed:4/13/2004
Keywords:kbBug kbKernBase kbnofix kbRegistry KB193465