当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 用C#实现启动另一程序的方法

ASP.NET
ASP.NET2.0向其它网页传递信息的方法
基于 pureXML 技术的数据库表结构扩展
利用缓冲技术提高JSP程序的性能和稳定性
ASP.NET常用的三十三种实用代码
用ASP.Net实现在线压缩和解压缩
编程高手 ASP.NET 状态管理
flash菜单与asp.net进行交互
ASP.NET1.1中动态树的实现
ASP.NET 设计中的 N 个技巧
基于.NET平台的分层架构实战(五)接口的设计与实现
.NET平台依赖注入机制及IoC的设计与实现
依赖注入机制及IoC的设计与实现
数据访问层的第一种实现:Access+SQL
超简单实现 .NET开发类似Web Parts的功能
剖析ASP.NET AJAX的面向对象思想
WPF自定义漂亮的按钮样式
ASP.NET中常用的26个优化性能方法
用Xaml做网页框架
从UI->DB一条龙到代码生成到EOS,谈谈快速开发
ASP.NET ViewState 初探 (1)

ASP.NET 中的 用C#实现启动另一程序的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 65 ::
收藏到网摘: n/a

  一段实例代码,程序的目的是使用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);
  }
  }