获取注册表项的C#值 [英] Get value of registry key C#
本文介绍了获取注册表项的C#值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看了看现有的话题,所以请尽量从这里掉落的链接不要。
我希望得到一个注册表项的值 - 简单明了。以下是我有这么远。</ P>
注册地: 1)由下
关键 CURRENT_USER \ SOFTWARE \ Custom_Subkey \ Custom_Value \ Custom_key \ string_value
我试图找到* string_value *
字符串reg_subKey =SOFTWARE \\ Custom_Subkey \\ Custom_Value;
的RegistryKey根= Registry.CurrentUser.CreateSubKey(reg_subKey);
的foreach(在root.GetValueNames串键名())
{
textBox4.AppendText(keyname.ToString()+ Environment.NewLine);
//追加以下数据textBox4一旦在foreach完成:
//头1
//头2
// Header3
// Header4
// Header5
//现在,我想每个头的值:
使用(的RegistryKey键= root.OpenSubKey(键名))
{
** //此行获取突出了以下错误:
你调用的对象是空的。**
的MessageBox.show(key.ValueCount.ToString());
}
}
希望这是一个简单的修补程序。我期待着听到您的回复。 谢谢, 埃文
解决方案
我相信你想要 root.GetSubKeyNames()
的循环不是 GetValueNames ()
虽然价值正在得到我建议下面的循环中的值:
的foreach(在root.GetSubKeyNames字符串键名())
{
//使用键搞定值和设定textbox4
使用(的RegistryKey键= root.OpenSubKey(键名))
{
的MessageBox.show(key.ValueCount.ToString());
}
}
I have already looked at existing topics, so please try to refrain from dropping links here.
I want to get the value of a registry key - plain and simple. Here is what I have so far.
Registry: 1) Made a key under
Current_User\Software\Custom_Subkey\Custom_Value\Custom_key\string_value
I am trying to find the *string_value*
string reg_subKey = "Software\\Custom_Subkey\\Custom_Value";
RegistryKey root = Registry.CurrentUser.CreateSubKey(reg_subKey);
foreach (string keyname in root.GetValueNames())
{
textBox4.AppendText(keyname.ToString() + Environment.NewLine);
// Appends the following data to textBox4 once the foreach is completed:
// Header1
// Header2
// Header3
// Header4
// Header5
// Now I want to get the VALUES of each header:
using (RegistryKey key = root.OpenSubKey(keyname))
{
**// THIS LINE GETS HIGHLIGHTED WITH THE FOLLOWING ERROR:
"Object reference not set to an instance of an object.**"
MessageBox.Show(key.ValueCount.ToString());
}
}
Hopefully this is a simple fix. I look forward to hearing your responses. Thanks, Evan
解决方案
I believe you want root.GetSubKeyNames()
in the loop not GetValueNames()
While values is working to get the values I would suggest the following loop:
foreach(string keyname in root.GetSubKeyNames())
{
// use key to get value and set textbox4
using (RegistryKey key = root.OpenSubKey(keyname))
{
MessageBox.Show(key.ValueCount.ToString());
}
}
这篇关于获取注册表项的C#值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文