博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【用C#实现启动另一程序的方法】
阅读量:4289 次
发布时间:2019-05-27

本文共 1736 字,大约阅读时间需要 5 分钟。

一段实例代码,程序的目的是使用C#实现启动另一程序的方法。技术总监給出了我们这样一个有效的启动程序的有效方法,現在和大家分享下!

代码如下:

  private void btnCreate_Click(object sender, EventArgs e) 
  ...{ 
  int hWnd = FindWindow(null, "test");//窗體的名稱 
  //check if PowerReuse is launched or not 
  //if yes, pass path of project to PowerReuse 
  //or, launch PowerReuse with specified parameter 
  if (hWnd > 0) 
  ...{ 
  MessageBox.Show("powerReuse has been launched already." + " " + hWnd.ToString()); 
  //SendMessage to PowerReuse 
  return; 
  } 
  try 
  ...{ 
  Process Main_P = new Process(); 
  //this path should be retrieved from Windows Registry, 
  //the loaction is written by Installter during process of installation. 
  Main_P.StartInfo.FileName = @"C: est.exe";//運行的exe路徑 
  //This URL is passed to PowerReuse to open 
  Main_P.StartInfo.Arguments = @"C:Tempabc.prj";//運行時的參數 
  Main_P.StartInfo.UseShellExecute = true; 
  Main_P.Start(); 
  // 
  //we have to wait for a while until UI has been initialized 
  // 
  Main_P.WaitForInputIdle(10000); 
  //although UI has been initialzied, 
  //it does not mean main form of application has been completed. 
  //we may wait for another 10 seconds 
  for (int i = 0; i < 100; i++) 
  ...{ 
  hWnd = FindWindow(null, "PowerReuse (Beta)"); 
  //hWnd = Main_P.MainWindowHandle.ToInt32() ; 
  if (hWnd > 0) break; 
  Thread.Sleep(100); 
  } 
  //Here, we check if PowerReuse is fully launched 
  if (hWnd == 0) 
  ...{ 
  //Handle exception 
  MessageBox.Show("We cannot find window handle of PowerReuse"); 
  } 
  else 
  ...{ 
  //other handling 
  // 
  MessageBox.Show(hWnd.ToString() + " " + Main_P.MainWindowHandle.ToString() + " " + Main_P.MainWindowTitle); 
  } 
  } 
  catch (Exception ex) 
  ...{ 
  MessageBox.Show(ex.Message); 
  } 
  }
详细出处参考:http://www.jb51.net/article/39982.htm

转载地址:http://hwhgi.baihongyu.com/

你可能感兴趣的文章
fastdfs 图片服务器 使用java端作为客户端上传图片 / 【FastDFS专题】fastdfs使用实战(概念篇)
查看>>
Java互联网架构-Redis分布式缓存架构实现与原理解析
查看>>
让数据库不再成为业务发展瓶颈——分布式数据库架构设计
查看>>
java多线程有哪些实际的应用场景?
查看>>
分布式集群Session共享~多个tomcat7+redis的session共享实现
查看>>
实例|如何从两个List中筛选出相同的值
查看>>
搭建ECS云服务器(5)设置nginx+fastdfs+tomcat+redis开启自启动
查看>>
SSO单点登录的发展由来以及实现原理
查看>>
阿里巴巴,排行前10的开源项目,第一不是Dubbo!
查看>>
手把手教你新装的linux之后的必要配置(9)
查看>>
Java互联网架构-Spring分布式事务
查看>>
持久化框架:轻量级的关系型数据库中间件 Sharding-JDBC
查看>>
Java中如何实现分页功能
查看>>
简述架构演变过程中对session存储以及权限校验的不同的解决方案
查看>>
Spring Cloud是什么,和Dubbo对比如何?
查看>>
【Lucene】Apache Lucene全文检索引擎架构之入门实战
查看>>
【Lucene】Apache Lucene全文检索引擎架构之构建索引
查看>>
Apache Lucene全文检索引擎架构之搜索功能
查看>>
【Lucene】Apache Lucene全文检索引擎架构之中文分词和高亮显示
查看>>
搜索服务Solr集群搭建 使用ZooKeeper作为代理层
查看>>