用C#实现启动另一程序的方法实例
更新时间:2013年07月24日 11:02:50 作者:
一段实例代码,程序的目的是使用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);
}
}
相关文章
DevExpress设置TreeList图片节点背景色的方法
这篇文章主要介绍了DevExpress设置TreeList图片节点背景色的方法,需要的朋友可以参考下2014-08-08直接在线预览Word、Excel、TXT文件之ASP.NET
这篇文章主要用asp.net技术实现直接在线预览word、excel、txt文件,有需要的朋友可以参考下2015-08-08在c#中使用servicestackredis操作redis的实例代码
本篇文章主要介绍了在c#中使用servicestackredis操作redis的实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06
最新评论