您的位置:首页 > 数据库

C#检测目标机器上是否安装SQL SERVER软件

2007-12-24 12:18 393 查看
//测试退出SQL"服务管理器"后仍然能检测到当前机器上已安装SQL SERVER软件
//添加windows服务所需引用空间System.Service.Process.dll
using System.ServiceProcess;

//按钮事件:
private void button1_Click(object sender, System.EventArgs e)
{
if(ExistSqlServerService())
{
MessageBox.Show("本电脑已经安装SQL SERVER软件");
}
else
{
MessageBox.Show("本电脑还未安装SQL SERVER软件");
}
}

//调用判断函数

#region 自定义检测当前机器是否安装SQL2000方法
public static bool ExistSqlServerService()
{
bool ExistFlag=false;
ServiceController[] service=ServiceController.GetServices();
for(int i=0;i<service.Length;i++)
{
if (service[i].DisplayName.ToString()=="MSSQLSERVER")
{
ExistFlag=true;
}
}
return ExistFlag;
}
#endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: