爱情 (1) 安装 (2) 北斗 (1) 毕业 (1) 变量 (1) 测绘局 (1) 测量 (2) 插件 (1) 查询 (1) 常用 (1) 成果转化 (1) 词汇 (1) 慈善 (1) 答辩 (2) 代码 (2) 电台 (1) 发泄 (1) 感悟 (4) 高程 (1) 搞笑 (5) 共产党 (1) 古诗词 (1) 管理 (1) 函数 (3) 绘图 (1) 加密 (1) 交际 (1) 教程 (4) 教育 (2) 解决 (4) 解密 (1) 精度 (1) 酒桌 (2) 开源 (2) 科技 (1) 科学 (1) 刻录 (1) 老外 (1) 励志 (5) 连续剧 (1) 恋爱 (1) 列表 (1) 领导 (1) 美食 (2) 名人 (3) 命令 (4) 区别 (1) 日记 (2) 软件 (12) 商业 (3) 时政 (1) 视频 (1) 数据 (1) 算法 (1) 投影 (2) 图论 (1) 网络 (1) 网站 (1) 卫星 (3) 未成年 (1) 慰问 (1) 文本 (1) 文件 (2) 下载 (4) 笑话 (2) 学习 (9) 遥感 (1) 疑问 (5) 营销 (1) 娱乐 (3) 源代码 (2) 政策 (1) 指导 (3) 智慧 (5) 主成分分析 (2) 抓图 (1) 专家 (1) 资料 (5) 字符串 (1) 最短路径 (1) 坐标 (1) baidu (3) Bernese (1) blog (2) c# (9) China (3) Dijkstra (1) DNS (1) doris (1) dos (1) excel (1) firefox (3) GAMIT (8) gcc (1) GIS (3) GMT (1) GPS (5) ITRF (1) linux (5) mapx (1) matlab (6) movie (4) music (3) oracle (2) pic (1) PPT (3) PROJ.4 (2) python (2) QQ (2) rinex (1) shell (2) sql (1) teqc (3) tools (1) tps (1) ubuntu (5) USA (1) website (1)

博客归档

2010年5月7日星期五

c# 调用exe

http://zhidao.baidu.com/question/57228449.html
写的太复杂了
第一步:建立对象
第2步:启用多线程调用!

回答者: 新大软院 - 四级 2008-6-17 21:39

using System.Diagnostics;
如果是dos
Process.Start("cmd.exe");
如果是其他文件
Process.Start("绝对路径+文件名.exe");
------------------------------------
如何在c#中调用外部dos程序?
使用Process对象:
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.FileName="arj.exe" ;//需要启动的程序名
p.StartInfo.Arguments="-x sourceFile.Arj c:\temp";//启动参数
p.Start();//启动
if(p.HasExisted)//判断是否运行结束
p.kill();
-------------------------------------------------------------------------------------------------------------------------------------
///
/// 启动其他的应用程序
///

/// 应用程序名称
/// 应用程序工作目录
/// 命令行参数
/// 窗口风格
public static bool StartProcess(string file,string workdirectory,string args,ProcessWindowStyle style)
{
try
{
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(file,args);
startInfo.WindowStyle = style;
startInfo.WorkingDirectory = workdirectory;
myprocess.StartInfo = startInfo;
myprocess.StartInfo.UseShellExecute = false;
myprocess.Start();
return true;
}
catch(Exception e0)
{
MessageBox.Show("启动应用程序时出错!原因:" + e0.Message);
}
return false;
}



string parms = "" + GlobalObject.GetInstance().UserID + " " + GlobalObject.GetInstance().UserPassword;
if (PublicMethods.StartProcess(Application.StartupPath + @"\uptool\uptool.exe",Application.StartupPath + "\\UpTool",parms,ProcessWindowStyle.Normal))
{
Environment.Exit(0);
}
----------------------------------------------------------------------------------------------------------------------
Process.Start("IExplore.exe", "http://community.csdn.net/Expert/topic/4021/4021327.xml?temp=.9493524");
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo( );
startInfo.FileName = "执行EXE的文件名";
startInfo.Arguments = "参数数组";
System.Diagnostics.Process.Start( startInfo );
----------------------------------------------------------------------------------------------------------------------------
1.有好多时,我们需要调用外部的EXE程序,并且要等它运行完毕,我们才可以继续下面的动作,那我们怎样去实现了,请看以下代码.
'怎样等待外部程序运行完毕.
'从系统资料夹读入文件
Dim sysFolder As String = _
Environment.GetFoldERPath(Environment.SpecialFolder.System)
'创建一个新的进程结构
Dim pInfo As New ProcessStartInfo()
'设置其成员FileName为系统资料的Eula.txt
pInfo.FileName = sysFolder & "\eula.txt"
'运行该文件
Dim p As Process = Process.Start(pInfo)
'等待程序装载完成
p.WaitForInputIdle()
'等待进行程退出
p.WaitForExit()
'继续执行下面的代码
MessageBox.Show("继续执行代码")


2.我们想在5秒钟后,强行关闭它.而不是需要我手工关闭.
'设置退出时间
Dim timeOut As Integer = 5000
Dim sysFolder As String = _
Environment.GetFolderPath(Environment.SpecialFolder.System)
Dim pInfo As New ProcessStartInfo()
pInfo.FileName = sysFolder & "\eula.txt"
Dim p As Process = Process.Start(pInfo)
p.WaitForInputIdle()
p.WaitForExit(timeOut)
'检查是否在超时前已关闭了.
If p.HasExited = False Then
'进行程还在运行
'看进程有没有回应
If p.Responding Then
p.CloseMainWindow() '关闭窗口
Else
p.Kill() '强行中断
End If
End If
MessageBox.Show("继续执行代码")




复杂?! 他要用的代码就在里面,如果你自己看了,绝对能写出来自己。你提问题只是想要代码还是想学习啊?

没有评论:

发表评论

浏览统计