Registry.LocalMachine 字段

定义

包含本地计算机的配置数据。 此字段读取Windows注册表项HKEY_LOCAL_MACHINE。

public: static initonly Microsoft::Win32::RegistryKey ^ LocalMachine;
public static readonly Microsoft.Win32.RegistryKey LocalMachine;
 staticval mutable LocalMachine : Microsoft.Win32.RegistryKey
Public Shared ReadOnly LocalMachine 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_LOCAL_MACHINE
   // key in the registry of this machine.
   RegistryKey ^ rk = Registry::LocalMachine;
   
   // 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_LOCAL_MACHINE
        // key in the registry of this machine.
         RegistryKey rk = Registry.LocalMachine;

        // 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_LOCAL_MACHINE
        ' key in the registry of this machine.
        Dim rk As RegistryKey = Registry.LocalMachine
        
        ' 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

注解

LocalMachine 包含五个键:

硬件描述计算机中的物理硬件、设备驱动程序使用该硬件的方式,以及将内核模式驱动程序与用户模式代码链接在一起的映射和相关数据。 每次启动系统时,都会重新创建此密钥中的所有数据。 Description 子项描述了实际的计算机硬件。 DeviceMap 子项包含特定于特定驱动程序类的格式的杂项数据。 ResourceMap 子项描述哪些设备驱动程序声明哪些硬件资源。 Windows NT 诊断程序(Winmsdp.exe)可以以易于阅读的形式报告其内容。

SAM 用户和组帐户的安全信息的目录服务数据库,以及 Windows 2000 Server 中的域(SAM 是安全帐户管理器,称为目录服务数据库)。

安全性包含本地安全策略,例如特定的用户权限。 此密钥仅由 Windows 2000 安全子系统使用。

软件每台计算机软件数据库。 此密钥包含有关在本地计算机上安装的软件以及各种杂项配置数据的数据。

系统控制系统启动、设备驱动程序加载、Windows 2000 服务和操作系统行为。

按照约定,如果存在类似的数据,CurrentUserLocalMachine则优先使用CurrentUser数据。 但是,此键中的值还可以扩展 Registry.LocalMachine 中的数据(而不是替换)。 此外,某些项(如设备驱动程序加载条目)在 Registry.LocalMachine 外部发生时毫无意义。

适用于