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

ASP.NET
asp.net SqlParameter关于Like的传参数无效问题
数据库 数据类型float到C#类型decimal, float数据类型转化无效
google suggest 下拉菜单实现代码(asp.net版本)
asp.net(C#) 动态添加非ASP的标准html控件(如添加Script标签)
asp.net GridView导出到Excel代码
asp.net 开发的一些常用技巧
php 三级联动菜单
ASp.net 文本框(TextBox)计算,判断输入的是否是数字
asp.net 存储过程调用
asp.net 操作XML 按指定格式写入XML数据 WriteXml
asp.net连接数据库 增加,修改,删除,查询代码
VB.net 查询获取数据库数据信息
asp.net 删除,更新数据库方法
.net获取硬件信息_CPU序列号
ASP.NET 页面中动态增加的控件、添加事件
彻底解决ASP.NET MD5加密中文结果和ASP不一致的问题
asp.net结合aspnetpager使用SQL2005的存储过程分页
asp.net 用户控件读取以及赋值
asp.net 弹出警告窗口实现代码
asp.net 枚举文件里面的数字绑定到DropDownList里面去

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


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