Skip to main content
gamedev.net
🔒 Locked

[.net] REG_MULTI_SZ Problem

Started by Kryptus 1 reply 800+ views
Original Post
Kryptus
Kryptus
I'm programming an application in C# 2005 which makes use of the registry. The problem is I don't know how to display string array values! Here's what I have:

RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\lanmanserver\\Shares");

foreach (string shared in myKey.GetValueNames())
{
    MessageBox.Show(myKey.GetValue(shared).ToString());
    lvShared.Items.Add(shared);
}

myKey.Close();

If you look up that key in the registry you'll understand what I mean. How do I adapt my code to display all the contents of the string arrays?
mutex
mutex
It seems to return a String array for REG_MULTI_SZ values. Try this:

RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\lanmanserver\\Shares");foreach (string shared in myKey.GetValueNames()){    object value = myKey.GetValue(shared);    if (value is string[])    {        string[] values = (string[])value;        Console.WriteLine("{0} is a REG_MULTI_SZ consisting of {1} subvalues:", shared, values.Length);        foreach (string subvalue in values)        {            Console.WriteLine("  {0}", subvalue);        }    }    else    {        Console.WriteLine("{0}'s value is {1}", shared, value);    }}myKey.Close();

Kryptus
Kryptus
Yes that worked great! I learned a lot from that! Thanks again.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.