string strValue = "";
string strErrorMessage = "";
try
{
//SQL Server2000 SP4的值8.00.194
//string strPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion";
string strCurrentVersion = "";
RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey(@"Microsoft\MSSQLServer\MSSQLServer\CurrentVersion", true);
if (regkey == null)
{
strValue = "注册表的信息不包括SQL内容,请确认是否安装SQL";
}
else
{
strValue = regkey.GetValue("CurrentVersion").ToString();
}
}
catch (Exception ex)
{
strValue = "无法读取注册表的信息";
strErrorMessage = ex.Message.ToString();
}
labSql.Text = strValue;
SQL Server2000 SP4的值8.00.194
说明:
当时总结时确实只装了SQL2000,如果和SQL2005共存的话,找不到键值。
SQL2000和SQL2005共存情况,即安装过SQL2005的判断方法
1、SQL2000:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQL2000\MSSQLServer\CurrentVersion
2、SQL2005:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQL2005\MSSQLServer\CurrentVersion
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/09/09/1563039.html,如需转载请自行联系原作者