在.net中使用system.diaglostics.Process可以用來調用另一個命令行或程序。
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();
---------------------------------------------------------------------------------------- ------
/// <summary>
---------------------------------------------------------------------------- ----------------
/// 啟動其他的應用程序
/// </summary>
/// <param name="file">應用程序名稱</param>
/// <param name="workdirectory">應用程序工作目錄</param>
/// <param name="args">命令行參數</param>
/// <param name="style">窗口風格</param>
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 + @"uptooluptool.exe",Application.StartupPath + "UpTool",parms,ProcessWindowStyle.Normal))
{
Environment.Exit(0);
}