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

用C#实现启动另一程序的方法,第1张

用C#实现启动另一程序的方法,第2张

一段示例代码,程序的目的是用C#实现启动另一个程序的方法。技术总监给了我们这样一个有效的启动程序的方法,现在我想和大家分享一下:

private void btnCreate_Click(对象发送方,EventArgs e)
...{
int hWnd = FindWindow(null," test ");//表单名称
//检查是否启动了power reuse
//如果是,将项目的路径传递给power reuse
/或者,如果(hWnd > 0)则用指定的参数启动power reuse
...{
MessageBox。Show("powerReuse已经启动。"+ " " + hWnd。ToString());
//send message to power reuse
return;
}
尝试
...{
Process Main _ P = new Process();
//该路径应该从Windows注册表中检索,
//该动作是安装程序在安装过程中写入的。
Main _ P . startinfo . filename = @ " C:est . exe ";//exe路径运行
//此URL传递给power reuse打开
main _ p . startinfo . arguments = @ " c:tempabc . prj ";//运行时参数
main _ p . startinfo . useshellexecute = true;
Main _ P . Start();
//
//我们要等一段时间,直到UI已经初始化
//
Main _ P . WaitForInputIdle(10000);
//虽然UI已经初始化,
//但并不意味着应用程序的主窗体已经完成。
//我们可能会再等10秒
for(int I = 0;i < 100i++)
...{
hWnd = FindWindow(null," power reuse(Beta)");
//hWnd = Main _ P . Main window handle . toint 32();
if(hWnd > 0)break;
线程。睡眠(100);
}
//这里我们检查PowerReuse是否完全启动
if (hWnd == 0)
...{
//处理异常
MessageBox。Show("我们找不到PowerReuse的窗口句柄");
}
else
...{
//其他处理
//
MessageBox。显示(hWnd。ToString()+" "+Main _ P . mainwindowhandle . ToString()+" "+Main _ P . MainWindowTitle);
}
}
catch(Exception ex)
...{
MessageBox。显示(例如。消息);
}
}

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 用C#实现启动另一程序的方法

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情