用C#實現(xiàn)啟動另一程序的方法實例
更新時間:2013年07月24日 11:02:50 作者:
一段實例代碼,程序的目的是使用C#實現(xiàn)啟動另一程序的方法。技術(shù)總監(jiān)給出了我們這樣一個有效的啟動程序的有效方法,現(xiàn)在和大家分享下
復制代碼 代碼如下:
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";//運行時的參數(shù)
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);
}
}
相關(guān)文章
js substr,substring與java substring和C# substring的區(qū)別解析
本篇文章主要是對js中substr,substring與java中substring和C#中substring的區(qū)別進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
C#常用數(shù)據(jù)結(jié)構(gòu)棧的詳細介紹
在C#中,Stack<T> 是一個后進先出(LIFO,Last-In-First-Out)集合類,位于System.Collections.Generic 命名空間中,本文詳細介紹C#常用數(shù)據(jù)結(jié)構(gòu)棧,感興趣的朋友跟隨小編一起看看吧2024-09-09
C#實現(xiàn)多線程啟動停止暫停繼續(xù)的示例代碼
本文主要介紹了C#實現(xiàn)多線程啟動停止暫停繼續(xù)的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-01-01
ScriptControl控件執(zhí)行自定義VBS腳本示例分析
這篇文章主要介紹ScriptControl控件 msscript.ocx msscript.oca執(zhí)行自定義VBS腳本的示例代碼,需要的朋友可以參考下2013-04-04

