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

ASP.NET
ASP.NET ViewState 初探 (2)
.net中即时消息发送的实现
改写即时消息的发送 包含同时给多人发送信息
asp.NET特写
TreeView使用笔记
ASP.Net中自定义Http处理及应用之HttpHandler篇
Asp.net+Xml实现无数据库论坛一点即通
ASP.NET HTTP运行时组成详解
在ASP.NET 2.0中使用页面导航控件
ASP.net组件编程中的两种事件编写方法
保存图片流到数据库之后固定显示新法
asp.net 2.0中一次性更新所有GRIDVIEW的记录
ASP.NET创建Web服务之设计方针
用ASP.Net(C#)连接Oracle数据库的方法
ASP.Net环境下使用Jmail组件发送邮件
通过探测邮件服务器进行Email地址有效性检验
如何在上传的图片上打自己的文字水印
ASP.NET的14个热点问题解答
.NET中如何取得IP或者用户名等信息
ASP.NET中使用数据处理插入数据注意的问题

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 61 ::
收藏到网摘: 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);
  }
  }