Advertisement Jump to content
Sign in to follow this  
Kryptus

[.net] REG_MULTI_SZ Problem

This topic is 4897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!