用C#实现启动另一程序的方法
2008-08-21 10:49
573 查看
一段实例代码,程序的目的是使用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);
}
}
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#实现程序启动唯一实例的一种方法
- C#实现程序启动唯一实例的一种方法
- C# WinForm程序启动时不显示主窗体的实现方法
- c#实现程序启动唯一实例的一种方法
- C#实现程序开机启动的方法
- c#实现程序启动唯一实例的一种方法
- C#实现程序开机启动的方法
- WinCE C#程序,控制启动时仅仅能启动一个程序,使用相互排斥量来实现,该实现方法測试通过
- 在C#中启动另一个程序的实现方法
- C#程序实现软件开机自动启动的两种常用方法
- 【用C#实现启动另一程序的方法】
- [导入]在C#中启动另一个程序的实现方法[转载]
- c#实现程序启动唯一实例的方法
- c#实现程序启动唯一实例的一种方法
- C#实现程序的开机启动
- C#实现让程序只能打开一个实例(总结3方法)
- C# 实现启动欢迎界面的方法
- C# 启动外部程序的几种常用方法汇总
- C# 启动外部程序的几种方法: