国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:24:17
字體:
供稿:網(wǎng)友
下面以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)境下很容易的操作對(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)用很多命令自己可以研究下
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 白河县| 两当县| 伊宁县| 漠河县| 泾阳县| 千阳县| 河池市| 元朗区| 公主岭市| 若羌县| 垦利县| 焦作市| 修武县| 曲周县| 宝应县| 武隆县| 望城县| 黄山市| 海兴县| 泰安市| 汤原县| 察雅县| 农安县| 古蔺县| 西吉县| 华安县| 文昌市| 江川县| 霍林郭勒市| 华安县| 辽宁省| 固始县| 德化县| 裕民县| 清丰县| 苏尼特左旗| 淮滨县| 白玉县| 汕头市| 淮南市| 烟台市|