예제 #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);
        }
예제 #3
0
        /// <summary>
        /// 打开菜鸟运行
        /// </summary>
        /// <returns></returns>
        public static int SatrtCaiNiaoPrinter()
        {
            int result = 0;

            //如果菜鸟组件正在运行中 那么直接返回
            if (CheckCaiNiaoPrinterStatus() == IS_RUNING)
            {
                return(1);
            }

            try
            {
                var          caiNiaoInstallPath = string.Empty;
                SoftwareInfo model;
                var          resultCheck = SystemAppExtension.IsCaiNiaoPrintInstalled(out model);
                if (resultCheck == false)
                {
                    // throw new Exception("未能检测到菜鸟的安装!请从新安装菜鸟打印组件!");
                    //未能检测到菜鸟的安装  那么使用内置的菜鸟组件
                    model = new SoftwareInfo
                    {
                        InstallLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Replace("app", "CaiNiao"), CaiNiaoExcutePath)
                    };//替换到内置菜鸟组件目录
                }

                caiNiaoInstallPath = model.InstallLocation;

                var psInfo = new ProcessStartInfo {
                    FileName = caiNiaoInstallPath, UseShellExecute = true
                };
                Process.Start(psInfo);


                //var ps = ProcessUtil.CreateProcessAsUser(model.InstallLocation, "", ProcessUtil.SESSION_TYPE.SessionFromProcessExplorerSession);
                //if (null == ps)
                //{
                //    throw new BusinessException("未能正确启动,系统服务启动失败!请尝试手工运行菜鸟组件!");
                //}

                // ProcessHelper.CreateProcess(@"C:\Program Files (x86)\CaiNiao打印组件\CNPrintClient.exe", @"C:\Program Files (x86)\CaiNiao打印组件\");
            }
            catch (Exception ex)
            {
                throw new BusinessException("开启菜鸟打印组件运行出现异常,异常信息:{0}", ex.Message);
            }finally
            {
                if (result != 1)
                {
                    var localModel = new SoftwareInfo
                    {
                        InstallLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Replace("app", "CaiNiao"), CaiNiaoExcutePath)
                    };//替换到内置菜鸟组件目录
                    var psInfo = new ProcessStartInfo {
                        FileName = localModel.InstallLocation, UseShellExecute = true
                    };
                    Process.Start(psInfo);
                }


                result = CheckCaiNiaoPrinterStatus();
            }

            return(result);
        }