gpt4 book ai didi

c# - 获取注册表项 C# 的值

转载 作者:可可西里 更新时间:2023-11-01 13:28:26 24 4
gpt4 key购买 nike

我已经查看了现有主题,因此请尽量避免在此处删除链接。

我想获取注册表项的值 - 简单明了。这是我目前所拥有的。

注册表:1)在

下做了一个key

Current_User\Software\Custom_Subkey\Custom_Value\Custom_key\string_value

我正在尝试查找 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());
}
}

希望这是一个简单的修复。我期待听到您的回应。谢谢,埃文

最佳答案

我相信您希望在循环中使用 root.GetSubKeyNames() 而不是 GetValueNames()

虽然 values 正在努力获取值,但我建议使用以下循环:

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# - 获取注册表项 C# 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com