0

Hi i want to know how many lines of data there are in a regedit key of the user for example

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

In my case i have 10 lines of GUID's in there, so how do i do this in c#?

Plozy
  • 17
  • 3

1 Answers1

0

From that link Registry Data Types (exists next to value name in registry)

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 just edited it a bit to match your request.

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

        }
    }
}
RyuzakiH
  • 106
  • 1
  • 4