使用c#读取注册表项时出错

时间:2016-09-20 22:56:14

标签: c#

我在这个论坛上学到了这些代码。这些代码一直运行到上周。 只更改了我的电脑:Windows 10更新了最新版本。

我正在学习sql实例名称这个代码。

RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
        String[] instances = (String[])rk.GetValue("InstalledInstances");
        if (instances.Length > 0)
        {
            foreach (String element in instances)
            {
                if (element == "MSSQLSERVER")
                    Console.WriteLine(System.Environment.MachineName);
                else
                    Console.WriteLine(System.Environment.MachineName + @"\" + element);

            }
            Console.ReadLine();
        }

发生错误消息:system nullreference Exception。

我的注册表记录有InstalledInstances - > REG_MULTI_SZ - >恰克马克

但我正在阅读另一个注册表项。 例如,此代码正在运行。

 RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\90");
            string test = rk.GetValue("SharedCode").ToString(); MessageBox.Show(test);

我想在Windows更新后我的权利受到限制。

请帮助,谢谢。

0 个答案:

没有答案
相关问题