WEB开发网
开发学院软件开发C语言 让你的GUI程序随WINDOWS服务一起启动 阅读

让你的GUI程序随WINDOWS服务一起启动

 2009-05-14 08:28:31 来源:WEB开发网   
核心提示: 3.2 检查并启动对应GUI程序///<summary>///启动所有要启动的程序///</summary>privatevoidStartProgram(){try{foreach(stringProgramPathinrwCnfg.GsProgramPaths)

3.2 检查并启动对应GUI程序

/// <summary>
        /// 启动所有要启动的程序
        /// </summary>
        private void StartProgram()
        {
            try
            {
                foreach (string ProgramPath in rwCnfg.GsProgramPaths)
                {
                    string fileName = "";
                    //fileName = System.IO.Path.GetFileName(ProgramPath); //文件名
                    //string ext = System.IO.Path.GetExtension(ProgramPath); //扩展名
                    fileName = System.IO.Path.GetFileNameWithoutExtension(ProgramPath);// fileName.Replace(ext, "");
                    if (!IsExistProcess(fileName))
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo(ProgramPath);
                        startInfo.WindowStyle = ProcessWindowStyle.Normal;
                        Process.Start(startInfo);

                        Common.wLog("完成启动程序: " + fileName + ",完整路径:" + ProgramPath + " . " + System.DateTime.Now.ToString());

                        System.Threading.Thread.Sleep(3 * 1000); //间隔3秒;
                    }
                }
            }
            catch (Exception err)
            {
                Common.wLog(err.ToString());
            }

        }

        /// <summary>
        /// 检查该进程是否已启动
        /// </summary>
        /// <param name="processName"></param>
        /// <returns></returns>
        private bool IsExistProcess(string processName)
        {

            Process[] MyProcesses = Process.GetProcesses();
            foreach (Process MyProcess in MyProcesses)
            {
                if (MyProcess.ProcessName.CompareTo(processName) == 0)
                {
                    return true;

                }
            }
            return false;
        }

上一页  1 2 3 4 5  下一页

Tags:GUI 程序 WINDOWS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接