Asp.net/aspexecute the provisioning method and code

Source: Internet
Author: User
Tags net command

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.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;
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.