【用C#实现启动另一程序的方法】
来源:互联网 发布:智能仓库管理系统 源码 编辑:程序博客网 时间:2024/05/18 14:23
一段实例代码,程序的目的是使用C#实现启动另一程序的方法。xp系统之家技术总监給出了我们这样一个有效的启动程序的有效方法,現在雨林木风win7和大家分享下!
代码如下:
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);
}
}
详细出处参考:http://www.jb51.net/article/39982.htm
- 【用C#实现启动另一程序的方法】
- C#实现程序开机启动的方法
- 在C#中启动另一个程序的实现方法
- c#实现程序启动唯一实例的方法
- c#实现程序启动唯一实例的一种方法
- c#实现程序启动唯一实例的一种方法
- C#实现程序启动唯一实例的一种方法
- C#启动另一应用程序
- C# 实现程序的开机启动
- C# WinForm程序启动时不显示主窗体的实现方法
- 【转】C#启动另一应用程序
- C#实现程序开机启动
- C#实现简单聊天程序的方法
- C#程序如何连接另一台电脑的数据库
- Android Activity中启动另一应用程序的方法
- C# 启动外部程序的几种方法
- C# 启动外部程序的几种方法
- C# 启动外部程序的几种方法
- [poj 1611]The Suspects[并查集模板][递归与非递归实现]
- 创业干货分享:初创公司移动应用开发工具库(集合)
- Linux chattr命令
- VS2008 vs2008 error LNK2019: unresolved external symbol
- Ubuntu 12.10下安装 jdk-7u10-linux-x64.tar.gz
- 【用C#实现启动另一程序的方法】
- 内置函数numtodsinterval增加小时,分钟和秒
- SIP学习笔记(1)----消息集合
- Xcode 快捷操作
- 浏览发布的网站首页的时候,不能加载某个项,磁盘空间不足的
- 终端服务默认3389端口更改方法
- Oracle导出表(即DMP文件)的两种方法
- 零代码实战 SharePoint 2013 BCS:三、实干篇
- Python os.path模块