//此代码应用于,检测系统是否安装需要的组件//如果系统没有安装需要的组件,则执行此段代码//此段代码是应用于某个项目中的,所以只供参考//需要引用的命名空间using System.Windows; public void AccessInstat() { string tempType = null; object releaseType = null,uninstallString = null,displayName = null; RegistryKey currentKey = null; string[] temp = new string[] { "Microsoft System CLR Types for SQL Server 2012", "Microsoft .NET Framework 4.5 SDK" }; // int softNum = 0; RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键 try { foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键 { currentKey = pregkey.OpenSubKey(item); displayName = currentKey.GetValue("DisplayName"); //获取显示名称 uninstallString = currentKey.GetValue("UninstallString"); //获取卸载字符串路径 releaseType = currentKey.GetValue("ReleaseType"); //发行类型,值是Security Update为安全更新,Update为更新 bool isSecurityUpdate = false; if (releaseType != null) { tempType = releaseType.ToString(); if (tempType == "Security Update" || tempType == "Update") isSecurityUpdate = true; } if (!isSecurityUpdate && displayName != null && uninstallString != null) { switch (displayName.ToString()) { case "Microsoft System CLR Types for SQL Server 2012": temp[0] = null; break; case "Microsoft .NET Framework 4.5 SDK": temp[1] = null; break; } } } //未安装组件弹窗显示 if (temp[0] != null || temp[1] != null) { MessageBoxCus.ShowDialogs(temp, MessageBoxImage.Warning); } } catch (Exception E) { MessageBox.Show(E.Message.ToString()); } pregkey.Close(); } }
获取系统安装的软件名字 组件
最新推荐文章于 2024-07-02 16:41:16 发布