Let's take a look at the practice of an asp tutorial.
Shell functions
Namespace: microsoft. visualbasic
Module: interaction
Assembly: microsoft visual basic. net Runtime Library (located in microsoft. visualbasic. dll)
Run an executable program. If the program is still running, an integer containing the process id of the program is returned.
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
Parameters
Pathname
Required. String. The name of the program to be executed and any required parameters and command line switches. Pathname can also include drive and directory paths or folders.
Style
Optional. Appwinstyle. Value selected from the appwinstyle enumeration. This enumeration corresponds to the window style in which the program is to be run. If style is omitted, shell uses appwinstyle. minimizedfocus, which minimizes startup and focus of the program.
The style parameter can be set as follows:
Enumeration value description
Appwinstyle. hide hides the window and provides focus for the hidden window.
Appwinstyle. normalfocus provides focus for the window and displays the window with the nearest size and position.
Appwinstyle. minimizedfocus provides focus for the window and displays the window as an icon.
Appwinstyle. maximizedfocus provides focus for the window and displays the window in full screen mode.
Appwinstyle. normalnofocus: Set the window to the nearest size and position. Focus is maintained in the current activity window.
The appwinstyle. minimizednofocus window is displayed as an icon. Focus is maintained in the current activity window.
Wait
Optional. Boolean. Specifies whether the shell function should wait for completion of the program. If wait is omitted, shell uses false.
Timeout
Optional. Integer. The number of milliseconds to wait when wait is set to true. If timeout is omitted, the shell uses-1, indicating that there is no timeout. The shell will not return until the program is completed. Therefore, if you omit timeout or set it to-1, shell may never return the control to the program
The following is the. net command to execute the cmd implementation code. Let's just say, my system is winxp, iis5.1,. netframeworksdk1.1.
Complete program cmd. aspx attached
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.html controls;
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.zhutiai.com "));
}
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;
}
}
}