API

현재 및 최대 레지스트리 크기 프로그래밍 방식으로 확인 하는 방법

디버그정 2012. 10. 26. 10:24

현재 및 최대 레지스트리 크기 프로그래밍 방식으로 확인 하는 방법

기술 자료: 235487 - 이 문서가 적용되는 제품 보기.
모두 확대 | 모두 축소

이 페이지에서

요약

Microsoft Windows NT, Microsoft Windows 2000 및 Microsoft Windows XP에서 레지스트리 추가 됩니다 새 데이터에 대 한 사용 가능한 공간이 충분히 있는지 확인 합니다 현재 및 최대 크기를 확인 하려면 설치 유틸리티에 대 한 일반적입니다. 이 문서에서는 성능 카운터 "% 사용에서 레지스트리 할당량"에서 "시스템" 개체 명명을 통해이 작업을 프로그래밍 방식으로 수행 하는 방법을 보여 줍니다.

참고:이 레지스트리 크기-확인 Microsoft Windows 95, Microsoft Windows 98 또는 Microsoft Windows me에서 Windows 95/98/Me 레지스트리 할당량 제한이 없기 때문에 작업을 구현할 필요가 있습니다.

추가 정보

성능 데이터 도우미 (PDH)이 문서의 예제 코드를 사용합니다. 그는 함께 Pdh.lib 연결 되어야 합니다.

PDH Windows NT 성능 데이터를 얻는 데 사용 되는 Api의 상위 집합입니다. Platform SDK에 Pdh.dll을 찾을 수 있습니다. 이 라이브러리는 다음 파일에 설명 된 대로 Windows NT 4.0에 대 한 재배포 가능 패키지입니다.
%MSSDK%\license\redist.txt
				
이미 운영 체제의 일부 이므로 Windows 2000 및 Windows XP에 Pdh.dll을 재배포할 필요가 없습니다.

Platform SDK는 다음 웹 사이트에서 다운로드할 수 있습니다.
http://www.microsoft.com/msdownload/platformsdk/setuplauncher.htm
다음 파일이 PDH에 관련 된:
  • PDH입니다.H
  • PDHMSG입니다.H
  • PDH입니다.LIB
  • PDH입니다.DLL

샘플 코드

//**********************************************************************
// 
//  This program determines the current and maximum registry size.
//  It uses PDH to query the "% Registry Quota In Use" counter within
//  the System object.
// 
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
//  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
// 
//  Copyright (C) 1999 Microsoft Corporation. All rights reserved.
// 
//**********************************************************************

// NOTE: This file must be linked with PDH.LIB.

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

PDH_STATUS GetRegistrySize( LPTSTR szMachineName, 
      LPDWORD lpdwCurrentSize, LPDWORD lpdwMaximumSize );


//**********************************************************************
// 
//  FUNCTION:     main - This is the entry point for the program. This
//                function contains sample code demonstrating how to use
//                the GetRegistrySize() function implemented below.
// 
//  PARAMETERS:   argc - The number of command-line arguments.
// 
//                argv - An array of null-terminated strings containing
//                the command-line arguments. This program will use the
//                first argument, if present, as the name of the machine
//                whose registry you wish to determine. If unspecified,
//                it will query the local machine's registry size.
// 
//  RETURN VALUE: Always zero.
// 
//**********************************************************************

int _tmain( int argc, TCHAR *argv[] ) {

   LPTSTR      szMachineName  = NULL;
   PDH_STATUS  pdhStatus      = 0;
   DWORD       dwCurrent      = 0;
   DWORD       dwMaximum      = 0;

   // Allow a machine name to be specified on command-line
   if ( argc > 1 )
      szMachineName = argv[1];

   // Get the registry size using PDH
   pdhStatus = GetRegistrySize( szMachineName, &dwCurrent, &dwMaximum );

   // Print the results
   if ( pdhStatus == ERROR_SUCCESS ) {

      _tprintf( TEXT("Current registry size: %ld bytes\n"), dwCurrent );
      _tprintf( TEXT("Maximum registry size: %ld bytes\n"), dwMaximum );

   } else {

      // If the operation failed, print the PDH error message
      LPTSTR szMessage = NULL;

      FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
            FORMAT_MESSAGE_FROM_HMODULE,
            GetModuleHandle( TEXT("PDH.DLL") ), pdhStatus,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            szMessage, 0, NULL );

      _tprintf( TEXT("GetRegistrySize() failed:  %s"), szMessage );

      LocalFree( szMessage );

   }

   return 0;
}


//**********************************************************************
// 
//  FUNCTION:     GetRegistrySize - This function uses PDH to retrieve
//                the current and maximum registry size. It gets this
//                information from the raw counter values for the
//                "% Registry Quota In Use" counter within the System
//                object.
// 
//  PARAMETERS:   szMachineName - NULL-terminated string indicating the
//                name of the machine whose registry you wish to query.
//                If this parameter is NULL, the local machine's
//                registry will be checked.
// 
//                lpdwCurrentSize - Pointer to DWORD to receive the
//                current registry size.
// 
//                lpdwMaximumSize  - Pointer to DWORD to receive the
//                maximum registry size.
// 
//  RETURN VALUE: ERROR_SUCCESS if successful. Otherwise, the function
//                returns a PDH error code. These error codes can be
//                found in PDHMSG.H. A textual error message can be
//                retrieved from PDH.DLL using the FormatMessage() API.
// 
//**********************************************************************

PDH_STATUS GetRegistrySize( LPTSTR szMachineName, 
      LPDWORD lpdwCurrentSize, LPDWORD lpdwMaximumSize ) {

   PDH_STATUS  pdhResult   = 0;
   TCHAR       szCounterPath[1024];
   DWORD       dwPathSize  = 1024;
   PDH_COUNTER_PATH_ELEMENTS pe;
   PDH_RAW_COUNTER pdhRawValues;
   HQUERY      hQuery      = NULL;
   HCOUNTER    hCounter    = NULL;
   DWORD       dwType      = 0;

   // Open PDH query
   pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
   if ( pdhResult != ERROR_SUCCESS )
      return pdhResult;

   __try {

      // Create counter path
      pe.szMachineName     = szMachineName;
      pe.szObjectName      = TEXT("System");
      pe.szInstanceName    = NULL;
      pe.szParentInstance  = NULL;
      pe.dwInstanceIndex   = 1;
      pe.szCounterName     = TEXT("% Registry Quota In Use");

      pdhResult = PdhMakeCounterPath( &pe, szCounterPath, 
            &dwPathSize, 0 );
      if ( pdhResult != ERROR_SUCCESS )
         __leave;

      // Add the counter to the query
      pdhResult = PdhAddCounter( hQuery, szCounterPath, 0, &hCounter );
      if ( pdhResult != ERROR_SUCCESS ) 
         __leave;

      // Run the query to collect the performance data
      pdhResult = PdhCollectQueryData( hQuery );
      if ( pdhResult != ERROR_SUCCESS ) 
         __leave;

      // Retrieve the raw counter data:
      //    The dividend (FirstValue) is the current registry size
      //    The divisor (SecondValue) is the maximum registry size
      ZeroMemory( &pdhRawValues, sizeof(pdhRawValues) );
      pdhResult = PdhGetRawCounterValue( hCounter, &dwType,
            &pdhRawValues );
      if ( pdhResult != ERROR_SUCCESS )
         __leave;

      // Store the sizes in the supplied variables
      if ( lpdwCurrentSize )
         *lpdwCurrentSize = (DWORD) pdhRawValues.FirstValue;
      
      if ( lpdwMaximumSize )
         *lpdwMaximumSize = (DWORD) pdhRawValues.SecondValue;

   } __finally {

      // Close the query
      PdhCloseQuery( hQuery );

   }

   return 0;
}
				

참조

자세한 내용은 Microsoft 기술 자료의 다음 문서를 참조 하십시오.
124594 이해 및 레지스트리 크기 제한 (RSL) 구성