一段实例代码程序的目的是使用C#实现启动另一程序的方法技术总监给出了我们这样一个有效的启动程序的有效方法现在和大家分享下
以下是引用片段
privatevoidbtnCreate_Click(objectsenderEventArgse)
{
inthWnd=FindWindow(nulltest);//窗体的名称
//checkifPowerReuseislaunchedornot
//ifyespasspathofprojecttoPowerReuse
//orlaunchPowerReusewithspecifiedparameter
if(hWnd>)
{
MessageBoxShow(powerReusehasbeenlaunchedalready++hWndToString());
//SendMessagetoPowerReuse
return;
}
try
{
ProcessMain_P=newProcess();
//thispathshouldberetrievedfromWindowsRegistry
//theloactioniswrittenbyInstallterduringprocessofinstallation
Main_PStartInfoFileName=@C:estexe;//运行的exe路径
//ThisURLispassedtoPowerReusetoopen
Main_PStartInfoArguments=@C:Tempabcprj;//运行时的参数
Main_PStartInfoUseShellExecute=true;
Main_PStart();
//
//wehavetowaitforawhileuntilUIhasbeeninitialized
//
Main_PWaitForInputIdle();
//althoughUIhasbeeninitialzied
//itdoesnotmeanmainformofapplicationhasbeencompleted
//wemaywaitforanotherseconds
for(inti=;i<;i++)
{
hWnd=FindWindow(nullPowerReuse(Beta));
//hWnd=Main_PMainWindowHandleToInt();
if(hWnd>)break;
ThreadSleep();
}
//HerewecheckifPowerReuseisfullylaunched
if(hWnd==)
{
//Handleexception
MessageBoxShow(WecannotfindwindowhandleofPowerReuse);
}
else
{
//otherhandling
//
MessageBoxShow(hWndToString()++Main_PMainWindowHandleToString()++Main_PMainWindowTitle);
}
}
catch(Exceptionex)
{
MessageBoxShow(exMessage);
}
}