最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

最新評(píng)論

射洪县| 德州市| 仁寿县| 黄大仙区| 乡城县| 肇庆市| 湖州市| 兰考县| 健康| 玉田县| 鹤壁市| 易门县| 阿拉尔市| 西畴县| 布尔津县| 嘉义县| 清流县| 汉川市| 调兵山市| 曲阜市| 潮州市| 扎赉特旗| 垫江县| 武强县| 田阳县| 铜鼓县| 双桥区| 五大连池市| 朝阳市| 辽源市| 广平县| 蓬莱市| 哈尔滨市| 嫩江县| 荆州市| 于田县| 马关县| 莫力| 桑植县| 泾源县| 卫辉市|