本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/WYZSC/archive/2008/11/24/3360688.aspx
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
VS2005 C# winform
说明:
当时总结时确实只装了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