检查注册表项中有多少行数据

Check how many lines there are of data in a regedit key

你好,我想知道用户的注册表编辑器密钥中有多少行数据

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SystemInformation\ComputerHardwareIds

在我的例子中,我有 10 行 GUID,那么我如何在 C# 中执行此操作?

来自 link Registry Data Types(存在于注册表中的值名称旁边)

REG_SZ Null-terminated string. It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.
REG_MULTI_SZ Array of null-terminated strings that are terminated by two null characters.

Depending on that answer 只是稍微编辑了一下以符合您的要求。

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\SystemInformation"))
{
    if (key != null)
    {
        object value = key.GetValue("ComputerHardwareIds");
        if (value != null)
        {
            var computerHardwareIds = (value as string[]); // cast value object to string array, because its type is REG_MULTI_SZ

            var lines_num = computerHardwareIds.Length; // then you can get lines number this way

        }
    }
}