예제 #1
0
        /// <summary>
        /// 获取系统中已经安装的软件列表
        /// </summary>
        /// <returns></returns>
        public static List <SoftwareInfo> GetAllClientInstalledApps()
        {
            List <SoftwareInfo> lstSoftInfos = new List <SoftwareInfo>();

            RegistryKey[] keys = new RegistryKey[] {
                // search in: CurrentUser
                Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"),
                // search in: LocalMachine_32
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"),
                // search in: LocalMachine_64
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
            };


            foreach (var keyItem in keys)
            {
                var key = keyItem;
                if (null != key)
                {
                    foreach (String keyName in key.GetSubKeyNames())
                    {
                        var modInfo = SystemAppExtension.InitSoftInfoModelFromRegistryKey(ref key, keyName);
                        if (null != modInfo)
                        {
                            lstSoftInfos.Add(modInfo);
                        }
                    }
                }
            }


            return(lstSoftInfos);
        }
예제 #2
0
        /// <summary>
        /// 检测菜鸟打印组件是否安装到客户机
        /// </summary>
        /// <param name="modelInfo"></param>
        /// <returns></returns>
        public static bool IsCaiNiaoPrintInstalled(out SoftwareInfo modelInfo)
        {
            bool result = false;


            modelInfo = null;



            RegistryKey[] keys = new RegistryKey[] {
                // search in: CurrentUser
                Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"),
                // search in: LocalMachine_32
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"),
                // search in: LocalMachine_64
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
            };

            bool isCanStop = false;

            foreach (var keyItem in keys)
            {
                if (isCanStop == true)
                {
                    break;
                }
                var key = keyItem;
                if (null != key)
                {
                    foreach (String keyName in key.GetSubKeyNames())
                    {
                        RegistryKey subkey      = key.OpenSubKey(keyName);
                        string      displayName = subkey.GetValue("DisplayName") as string;

                        if (!string.IsNullOrEmpty(displayName) && displayName.Contains(CaiNiaoPrintName))
                        {
                            modelInfo = SystemAppExtension.InitSoftInfoModelFromRegistryKey(ref key, keyName);

                            //获取安装路径
                            if (string.IsNullOrEmpty(modelInfo.InstallLocation))
                            {
                                if (!string.IsNullOrEmpty(modelInfo.UninstallString))
                                {
                                    string installDir = Path.GetDirectoryName(modelInfo.UninstallString);
                                    modelInfo.InstallLocation = Path.Combine(installDir, CaiNiaoExcutePath);
                                }
                            }
                            result    = true;
                            isCanStop = true;
                            break;
                        }
                    }
                }
            }

            return(result);
        }