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

//测试退出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

posted on 2007-12-24 12:18  风灵溪清  阅读(173)  评论(0编辑  收藏  举报

导航