欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在asp.net(c#)下實(shí)現(xiàn)調(diào)用cmd的方法

 更新時(shí)間:2012年01月09日 11:20:01   作者:  
通常情況下我們會用到調(diào)用cmd.exe來實(shí)現(xiàn)一些命令,例如 ping ,等等
下面以ping 為例用到命名空間System.Diagnostics;
System.Diagnostics 命名空間 包含了能夠與系統(tǒng)進(jìn)程 事件日志 和性能計(jì)數(shù)器進(jìn)行交互的類 一般用于幫助診斷和調(diào)試應(yīng)用程序 例如 Debug類用于幫組調(diào)試代碼 Process類能夠控制進(jìn)程訪問 Trace類能夠跟蹤代碼的執(zhí)行情況
Process 用于操作本地或者遠(yuǎn)程進(jìn)程打訪問 通過Process 可以在托管環(huán)境下很容易的操作對外部進(jìn)程的啟動(dòng)或者停止 。
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace TestEqual
{
class Program
{
static void Main(string[] args)
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "iexplore.exe";
myProcess.StartInfo.Arguments = "http://www.baidu.com";
myProcess.Start();
}

}
}

必須設(shè)置相應(yīng)的FileName和Arguments屬性
下面以ping為例
代碼如下:
復(fù)制代碼 代碼如下:

string hostname = "http://www.baidu.com"; //或者這里是ip等;
Process prc=new Process();
prc.StartInfo.FileName="cmd.exe";
prc.StartInfo.UseShellExecute=false;
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.StartInfo.RedirectStandardError = true;
prc.StartInfo.CreateNoWindow = false;
prc.Start();
prc.StandardInput.WriteLine("ping " + hostname);
prc.StandardInput.Close();
Response.Write(prc.StandardOutput.ReadToEnd());

這里還可以調(diào)用很多命令自己可以研究下

相關(guān)文章

最新評論