            <<< DECWET::DOCD$:[NOTES$LIBRARY]NT-DEVELOPERS.NOTE;1 >>>
                         -< MS Windows NT Developers >-
================================================================================
Note 3110.5                       system model?                           5 of 5
HYDRA::PASHAPOUR "Disk space, the final frontier"   156 lines  11-NOV-1996 08:04
                         -< here is the code for it. >-
--------------------------------------------------------------------------------
    For those who may need it, below is the code I put together. Let me
    know, if you run into any problems with it.
    
    Amin
    
#include <windows.h>
#include <winreg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX_VALUE_NAME              128
#define MAX_DATA_LEN                1024


/************************************************************************\
*
*  FUNCTION: GetID();
*
*  PURPOSE:  To obtain the system ID from the registry.
*
\************************************************************************/


VOID GetID (LPBYTE bInfo)
  {
  HKEY hKeyRoot = HKEY_LOCAL_MACHINE;
  CHAR RegPath[MAX_PATH]  = "HARDWARE\\DESCRIPTION\\System";
 
  HKEY   hKey;
  CHAR   ValueName[MAX_VALUE_NAME];
  DWORD  cbValueName = MAX_VALUE_NAME;
  DWORD  dwType;
  DWORD  retCode;
  LONG   CLOSEKEY;

  CHAR   ClassName[MAX_PATH];
  DWORD  dwcClassLen = MAX_PATH;
  DWORD  dwcSubKeys;
  DWORD  dwcMaxSubKey;
  DWORD  dwcMaxClass;
  DWORD  dwcValues;
  DWORD  dwcMaxValueName;
  DWORD  dwcMaxValueData;
  DWORD  dwcSecDesc;
  FILETIME  ftLastWriteTime;

  DWORD  cbData;

  // OPEN THE KEY.

  retCode = RegOpenKeyEx (hKeyRoot,    // Key handle at root level.
                          RegPath,     // Path name of child key.
                          0,           // Reserved.
                          KEY_EXECUTE, // Requesting read access.
                          &hKey);      // Address of key to be returned.

  if (retCode)
    {
    printf ( "Error: RegOpenKeyEx = %d", retCode);
    return;
    }

// ADD A QUERY AND ALLOCATE A BUFFER FOR BDATA.

  retCode =
  RegQueryInfoKey (hKey,              // Key handle.
                   ClassName,         // Buffer for class name.
                   &dwcClassLen,      // Length of class string.
                   NULL,              // Reserved.
                   &dwcSubKeys,       // Number of sub keys.
                   &dwcMaxSubKey,     // Longest sub key size.
                   &dwcMaxClass,      // Longest class string.
                   &dwcValues,        // Number of values for this key.
                   &dwcMaxValueName,  // Longest Value name.
                   &dwcMaxValueData,  // Longest Value data.
                   &dwcSecDesc,       // Security descriptor.
                   &ftLastWriteTime); // Last write time.

   if (retCode)
    {
    printf ( "Error: RegQIK = %d, %d", retCode, __LINE__);
    }

     cbData = dwcMaxValueData;


  // ENUMERATE THE KEY.

  retCode = RegEnumValue (hKey,        // Key handle returned from RegOpenKeyEx.
                          1,           // For Identifier
                          ValueName,   // Name of value.
                          &cbValueName,// Size of value name.
                          NULL,        // Reserved, dword = NULL.
                          &dwType,     // Type of data.
                          bInfo,       // Data buffer.
                          &cbData);    // Size of data buffer.

  if (retCode != ERROR_SUCCESS)
    {

    if (dwType < REG_FULL_RESOURCE_DESCRIPTOR)
      {
      printf ( "Error: RegEnumValue = %d, cbData = %d, line %d",
                retCode, cbData, __LINE__);
      }
    }


  switch (dwType)
    {
//    REG_NONE                    ( 0 )   // No value type
//    REG_SZ                      ( 1 )   // Unicode nul terminated string
//    REG_EXPAND_SZ               ( 2 )   // Unicode nul terminated string
                                          // (with environment variable references)
//    REG_BINARY                  ( 3 )   // Free form binary
//    REG_DWORD                   ( 4 )   // 32-bit number
//    REG_DWORD_LITTLE_ENDIAN     ( 4 )   // 32-bit number (same as REG_DWORD)
//    REG_DWORD_BIG_ENDIAN        ( 5 )   // 32-bit number
//    REG_LINK                    ( 6 )   // Symbolic Link (unicode)
//    REG_MULTI_SZ                ( 7 )   // Multiple Unicode strings
//    REG_RESOURCE_LIST           ( 8 )   // Resource list in the resource map
//    REG_FULL_RESOURCE_DESCRIPTOR ( 9 )  // Resource list in the hardware description

    case REG_NONE:
      printf ("REG_NONE: No defined value type. \n");
      break;

    case REG_SZ:
      // printf ( "REG_SZ: Idenifier A null-terminated Unicode string.\n");
	  // This is the one we were looking for.
      break;

    default:
      printf ("Undefine in this verion of the Registry. %d \n",
               dwType);
      break;

    } // end switch
    CLOSEKEY = RegCloseKey (hKey);   // Close the key handle.
	if(CLOSEKEY != ERROR_SUCCESS)
		    printf ( "Error: RegCloseKey = %d \n", CLOSEKEY);
  }

  int main ()
{
  BYTE bInfo[256];

  GetID( bInfo);
  printf ("The ID of this machine is %s \n",bInfo);


  return 0;

}

    
