【www.gdgbn.com--Action】

先来看一款asp教程的做法

shell 函数
命名空间:microsoft.visualbasic
模块:interaction
程序集:microsoft visual basic .net 运行库(位于 microsoft.visualbasic.dll 中)
运行一个可执行程序,并且如果该程序仍然在运行,则返回一个包含该程序的进程 id 的整数。
public function shell( _
byval pathname as string, _
optional byval style as appwinstyle = appwinstyle.minimizedfocus, _
optional byval wait as boolean = false, _
optional byval timeout as integer = -1 _
) as integer
参数
pathname
必选项。字符串。要执行的程序名以及任何需要的参数和命令行开关。pathname 还可以包括驱动器和目录路径或文件夹。
style
可选项。appwinstyle。从 appwinstyle 枚举中选择的值,该枚举与要在其中运行程序的窗口样式相对应。如果省略 style,则 shell 使用 appwinstyle.minimizedfocus,这将使程序以最小化启动并具有焦点。
style 参数可以有以下设置之一:
枚举值 说明
appwinstyle.hide 隐藏窗口并为隐藏的窗口提供焦点。
appwinstyle.normalfocus 为窗口提供焦点,并以最近的大小和位置显示窗口。
appwinstyle.minimizedfocus 为窗口提供焦点,并以图标的形式显示窗口。
appwinstyle.maximizedfocus 为窗口提供焦点,并以全屏方式显示窗口。
appwinstyle.normalnofocus 将窗口设置为最近的大小和位置。当前活动窗口保持焦点。
appwinstyle.minimizednofocus 以图标的形式显示窗口。当前活动窗口保持焦点。

wait
可选项。boolean。指示 shell 函数是否应等待程序完成的值。如果省略 wait,则 shell 使用 false。
timeout
可选项。integer。wait 为 true 时等待完成的毫秒数。如果省略 timeout,则 shell 使用 -1,表示没有超时,shell 直到程序完成时才返回。因此,如果省略 timeout 或将它设置为 -1,则 shell 可能永远不会将控制返回给程序

下面是.net执行cmd实现代码顺手说一哈,我的系统winxp,iis5.1,.netframeworksdk1.1
完整程序cmd.aspx附上

using system;
using system.collections;
using system.configuration;
using system.data;
using system.linq;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.xml.linq;
using system.diagnostics;
namespace webform
{
public partial class _default : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
response.write(execommand("ping http://www.111cn.net "));
}
public string execommand(string commandtext)
{
process p = new process();
p.startinfo.filename = "cmd.exe";
p.startinfo.useshellexecute = false;
p.startinfo.redirectstandardinput = true;
p.startinfo.redirectstandardoutput = true;
p.startinfo.redirectstandarderror = true;
p.startinfo.createnowindow = true;
string stroutput = null;
try
{
p.start();
p.standardinput.writeline(commandtext);
p.standardinput.writeline("exit");
stroutput = p.standardoutput.readtoend();
p.waitforexit();
p.close();
}
catch (exception e)
{
stroutput = e.message;
}
return stroutput;
}
}
}

本文来源:http://www.gdgbn.com/flash/29179/