用C#实现启动另一程序的方法实例

时间:2023-06-20 12:05:43 


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);
}
}
标签:C#,启动,程序
0
投稿

猜你喜欢

  • 详解Kotlin和anko融合进行Android开发

    2021-08-15 19:34:16
  • Junit测试多线程无法得到结果的问题解决

    2023-01-01 22:12:52
  • SpringBoot项目@Async方法问题解决方案

    2023-11-12 03:55:26
  • C#11新特性使用案例详解

    2023-11-26 03:19:15
  • Android游戏开发:实现手势操作切换图片的实例

    2022-05-06 11:55:01
  • Android中Shape的用法详解

    2023-12-21 14:05:44
  • Android adb命令中pm工具的作用及用法说明

    2022-05-27 23:38:42
  • 读取spring配置文件的方法(spring读取资源文件)

    2022-10-08 11:24:21
  • SpringBoot整合WebSocket实现后端向前端发送消息的实例代码

    2021-10-30 19:24:56
  • Android中handler使用浅析

    2022-08-22 23:45:16
  • SpringMVC实现上传下载文件

    2022-11-10 03:18:14
  • java实现员工工资管理系统

    2023-09-22 15:37:24
  • C#类中static变量用法分析

    2022-06-20 16:14:23
  • C#控制台实现飞行棋小游戏

    2023-04-27 05:13:43
  • 详细分析android的MessageQueue.IdleHandler

    2023-06-23 19:12:10
  • Android入门之TabHost与TabWidget实例解析

    2022-12-07 23:03:42
  • 详解Spring Boot读取配置文件与配置文件优先级

    2022-03-23 13:14:23
  • java数学工具类Math详解(round方法)

    2022-09-10 17:01:00
  • Spring Boot ActiveMQ连接池配置过程解析

    2023-11-08 23:08:02
  • C#中ref关键字的用法

    2022-07-17 21:30:47
  • asp之家 软件编程 m.aspxhome.com