Win32.Registry表现神秘 [英] Win32.Registry behaves mysteriously

查看:103
本文介绍了Win32.Registry表现神秘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在需要我检查Sql Server实例是否存在的项目中,我找到了一些代码来检查适当的注册表项.但是,尽管代码看起来正确,但却无法正常工作.诊断它后,我发现尝试从Reg_Multi_SZ条目中检索值时代码失败.更进一步,我发现了这一点:

In a project that required me to check for the presence of Sql Server Instances I found some code that checked appropriate registry entries. But although the code looked correct it didn''t work. Diagnosing it, I found that the code failed when trying to retrieve values from a Reg_Multi_SZ entry. Going further I found this:

Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server")
For Each Name As String In rk.GetSubKeyNames()
    Console.WriteLine(Name)
Next


这将在"Microsoft SQL Server"键下产生一个子键列表.关键是:
100
90
ExceptionMessageBox
实例名称
MSSQL10.MSSQLSERVER
MSSQL10.SQLEXPRESS
MSSQLServer
RefCount
服务
XharedManagementObjects
SQLEXPRESS
SQLNCLI10
SqlWriter

但是相反,它给出了以下子项名称:
100
90
BOL
DACFramework
DACProjectSystem
RefCount
服务
SharedManagementObjects
SQLEXPRESS
SqlPubWiz
TSqlLanguageService


就像我访问的注册表项不同于我指定的注册表项.
任何人都可以解释为什么会发生这种情况以及如何纠正它吗?

环境:
Windows 7 Ultimate 64 SP1
Visual Studio 2010版本10.0.40219.1 SP1Rel
.Net 3.5


This should produce a list of subkeys under the "Microsoft SQL Server" key. The keys are:
100
90
ExceptionMessageBox
InstanceNames
MSSQL10.MSSQLSERVER
MSSQL10.SQLEXPRESS
MSSQLServer
RefCount
Services
XharedManagementObjects
SQLEXPRESS
SQLNCLI10
SqlWriter

But instead it gives these subkey names:
100
90
BOL
DACFramework
DACProjectSystem
RefCount
Services
SharedManagementObjects
SQLEXPRESS
SqlPubWiz
TSqlLanguageService


It acts as if I am accessing a different registry key than the one I am specifying.
Can anyone explain why this is occurring and how I can correct it?

Environment:
Windows 7 Ultimate 64 SP1
Visual Studio 2010 Version 10.0.40219.1 SP1Rel
.Net 3.5

推荐答案

为什么要检查注册表?您可以枚举网络上的服务器实例:

Why check the registry? You can just enumerate the server instances on your network:

SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
DataTable dt = instance.GetDataSources();
foreach (System.Data.DataRow row in dt.Rows)
    {
    Console.WriteLine("ServerName = {0}", row["ServerName"]);
    }


这篇关于Win32.Registry表现神秘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆