Share via


Registry.PerformanceData 欄位

定義

包含軟體元件的效能資訊。 這個欄位會讀取 Windows 登錄主要機碼 HKEY_PERFORMANCE_DATA。

public: static initonly Microsoft::Win32::RegistryKey ^ PerformanceData;
public static readonly Microsoft.Win32.RegistryKey PerformanceData;
 staticval mutable PerformanceData : Microsoft.Win32.RegistryKey
Public Shared ReadOnly PerformanceData As RegistryKey 

欄位值

範例

下列範例示範如何擷取此機碼的子機碼,並將其名稱列印到畫面。 OpenSubKey使用方法來建立感興趣的特定子機碼實例。 然後,您可以在 中使用 RegistryKey 其他作業來操作該索引鍵。 請注意,此範例通常不會傳回任何結果,因為可能沒有任何效能數據。

using namespace System;
using namespace Microsoft::Win32;
void PrintKeys( RegistryKey ^ rkey )
{
   
   // Retrieve all the subkeys for the specified key.
   array<String^>^names = rkey->GetSubKeyNames();
   int icount = 0;
   Console::WriteLine( "Subkeys of {0}", rkey->Name );
   Console::WriteLine( "-----------------------------------------------" );
   
   // Print the contents of the array to the console.
   System::Collections::IEnumerator^ enum0 = names->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      String^ s = safe_cast<String^>(enum0->Current);
      Console::WriteLine( s );
      
      // The following code puts a limit on the number
      // of keys displayed.  Comment it out to print the
      // complete list.
      icount++;
      if ( icount >= 10 )
            break;
   }
}

int main()
{
   
   // Create a RegistryKey, which will access the HKEY_PERFORMANCE_DATA
   // key in the registry of this machine.
   RegistryKey ^ rk = Registry::PerformanceData;
   
   // Print out the keys.
   PrintKeys( rk );
}
using System;
using Microsoft.Win32;

class Reg {
    public static void Main() {

        // Create a RegistryKey, which will access the HKEY_PERFORMANCE_DATA
        // key in the registry of this machine.
        RegistryKey rk = Registry.PerformanceData;

        // Print out the keys.
        PrintKeys(rk);
    }

    static void PrintKeys(RegistryKey rkey) {

        // Retrieve all the subkeys for the specified key.
        string [] names = rkey.GetSubKeyNames();

        int icount = 0;

        Console.WriteLine("Subkeys of " + rkey.Name);
        Console.WriteLine("-----------------------------------------------");

        // Print the contents of the array to the console.
        foreach (string s in names) {
            Console.WriteLine(s);

            // The following code puts a limit on the number
            // of keys displayed.  Comment it out to print the
            // complete list.
            icount++;
            if (icount >= 10)
                break;
        }
    }
}
Imports Microsoft.Win32

Class Reg
    
    Public Shared Sub Main()
        
        ' Create a RegistryKey, which will access the HKEY_PERFORMANCE_DATA 
        ' key in the registry of this machine.
        Dim rk As RegistryKey = Registry.PerformanceData
        
        ' Print out the keys.
        PrintKeys(rk)
    End Sub    
    
    Shared Sub PrintKeys(rkey As RegistryKey)
        
        ' Retrieve all the subkeys for the specified key.
        Dim names As String() = rkey.GetSubKeyNames()
        
        Dim icount As Integer = 0
        
        Console.WriteLine("Subkeys of " & rkey.Name)
        Console.WriteLine("-----------------------------------------------")
        
        ' Print the contents of the array to the console.
        Dim s As String
        For Each s In  names
            Console.WriteLine(s)
            
            ' The following code puts a limit on the number
            ' of keys displayed.  Comment it out to print the
            ' complete list.
            icount += 1            
            If icount >= 10 Then
                Exit For
            End If
        Next s
    End Sub
End Class

備註

每個軟體元件都會為其物件、安裝計數器時建立索引鍵,並在執行時寫入計數器數據。 您可以使用 函式存取此數據, RegistryKey 就像存取任何其他登錄數據一樣。

雖然您使用登錄來收集效能數據,但數據不會儲存在登錄資料庫中。 相反地,使用此機碼存取登錄會導致系統從適當的系統物件管理員收集數據。

若要從本機系統取得效能數據,請使用 GetValue 方法搭配 Registry.PerformanceData 機碼。 第一次呼叫會開啟密鑰 (您不需要先明確開啟密鑰) 。 不過,當您完成取得效能數據時,請務必使用 Close 方法來關閉密鑰的句柄。 用戶無法使用其效能數據時安裝或移除軟體元件。

若要從遠端系統取得效能數據,您必須使用 OpenRemoteBaseKey 方法,以及遠端系統和 Registry.PerformanceData 機碼的電腦名稱。 此呼叫會擷取代表遠端系統效能數據的索引鍵。 若要擷取數據,請使用此機碼呼叫 GetValue ,而不是 Registry.PerformanceData 機碼。

注意

在 Windows Server 2003 上,使用者至少必須屬於 效能監視器 Users 群組,才能存取此基底密鑰的子機碼。

適用於