C#检测目标机器上是否安装 IIS 和 SQL SERVER 软件
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
//测试退出 IIS 或 SQL服务管理器 后仍然能检测到当前机器上已安装 IIS 或 SQL SERVER 软件
//添加windows服务所需引用空间System.ServiceProcess,D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.ServiceProcess.dllusing System.ServiceProcess;//按钮事件,SQL Server为MSSQLSERVER,IIS为W3SVC,将下面的MSSQLSERVER改为W3SVC即可private void button1_Click(object sender, System.EventArgs e){ if(ExistSqlServerService("MSSQLSERVER")) { MessageBox.Show("本电脑已经安装SQL SERVER软件"); } else { MessageBox.Show("本电脑还未安装SQL SERVER软件"); }}//调用判断函数#region 自定义检测当前机器是否安装指定服务的方法public static bool ExistSqlServerService(string tem){ bool ExistFlag=false; ServiceController[] service=ServiceController.GetServices(); for(int i=0;i<service.Length;i++) { if (service[i].ServiceName.ToString()==tem) { ExistFlag=true; break; } } return ExistFlag;}#endregion
该文章在 2021/4/20 11:03:58 编辑过 |
关键字查询
相关文章
正在查询... |