需要 using System.Diagnostics;
using System.IO;
using System.IO;
一。方法1
public static string RunCommand(string command)
{
//實例一個Process類,啟動一個獨立進程
Process p = new Process();
public static string RunCommand(string command)
{
//實例一個Process類,啟動一個獨立進程
Process p = new Process();
//Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:
p.StartInfo.FileName = "cmd.exe"; //設定程序名
p.StartInfo.Arguments = "/c " + command; //設定程式執行參數
p.StartInfo.UseShellExecute = false; //關閉Shell的使用
p.StartInfo.Arguments = "/c " + command; //設定程式執行參數
p.StartInfo.UseShellExecute = false; //關閉Shell的使用